1 /* 7zTypes.h -- Basic types 2 2013-11-12 : Igor Pavlov : Public domain */ 3 4 module lzma.ztypes; 5 6 extern (C): 7 8 enum { 9 SZ_OK = 0, 10 11 SZ_ERROR_DATA = 1, 12 SZ_ERROR_MEM = 2, 13 SZ_ERROR_CRC = 3, 14 SZ_ERROR_UNSUPPORTED = 4, 15 SZ_ERROR_PARAM = 5, 16 SZ_ERROR_INPUT_EOF = 6, 17 SZ_ERROR_OUTPUT_EOF = 7, 18 SZ_ERROR_READ = 8, 19 SZ_ERROR_WRITE = 9, 20 SZ_ERROR_PROGRESS = 10, 21 SZ_ERROR_FAIL = 11, 22 SZ_ERROR_THREAD = 12, 23 24 SZ_ERROR_ARCHIVE = 16, 25 SZ_ERROR_NO_ARCHIVE = 17 26 } 27 28 alias SRes = int; 29 alias WRes = int; 30 31 alias Byte = ubyte; 32 alias Int16 = short; 33 alias UInt16 = ushort; 34 alias Int32 = int; 35 alias UInt32 = uint; 36 alias Int64 = long; 37 alias UInt64 = ulong; 38 alias SizeT = size_t; 39 alias Bool = bool; 40 enum { 41 False = 0, 42 True = 1 43 } 44 45 /* The following interfaces use first parameter as pointer to structure */ 46 47 struct IByteIn { 48 Byte function(void *p) Read; /* reads one byte, returns 0 in case of EOF or error */ 49 } 50 51 struct IByteOut { 52 void function(void *p, Byte b) Write; 53 } 54 55 struct ISeqInStream { 56 SRes function(void *p, void *buf, size_t *size) Read; 57 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. 58 (output(*size) < input(*size)) is allowed */ 59 } 60 61 /* it can return SZ_ERROR_INPUT_EOF */ 62 SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size); 63 SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType); 64 SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf); 65 66 struct ISeqOutStream { 67 size_t function(void *p, const void *buf, size_t size) Write; 68 /* Returns: result - the number of actually written bytes. 69 (result < size) means error */ 70 } 71 72 enum ESzSeek { 73 SZ_SEEK_SET = 0, 74 SZ_SEEK_CUR = 1, 75 SZ_SEEK_END = 2 76 } 77 78 struct ISeekInStream { 79 SRes function(void *p, void *buf, size_t *size) Read; /* same as ISeqInStream::Read */ 80 SRes function(void *p, Int64 *pos, ESzSeek origin) Seek; 81 } 82 83 struct ILookInStream { 84 SRes function(void *p, const void **buf, size_t *size) Look; 85 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. 86 (output(*size) > input(*size)) is not allowed 87 (output(*size) < input(*size)) is allowed */ 88 SRes function(void *p, size_t offset) Skip; 89 /* offset must be <= output(*size) of Look */ 90 91 SRes function(void *p, void *buf, size_t *size) Read; 92 /* reads directly (without buffer). It's same as ISeqInStream::Read */ 93 SRes function(void *p, Int64 *pos, ESzSeek origin) Seek; 94 } 95 96 SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size); 97 SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset); 98 99 /* reads via ILookInStream::Read */ 100 SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType); 101 SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size); 102 103 enum LookToRead_BUF_SIZE = (1 << 14); 104 105 struct CLookToRead { 106 ILookInStream s; 107 ISeekInStream *realStream; 108 size_t pos; 109 size_t size; 110 Byte[1 << 14] buf; 111 } 112 113 void LookToRead_CreateVTable(CLookToRead *p, int lookahead); 114 void LookToRead_Init(CLookToRead *p); 115 116 struct CSecToLook { 117 ISeqInStream s; 118 ILookInStream *realStream; 119 } 120 121 void SecToLook_CreateVTable(CSecToLook *p); 122 123 struct CSecToRead { 124 ISeqInStream s; 125 ILookInStream *realStream; 126 } 127 128 void SecToRead_CreateVTable(CSecToRead *p); 129 130 struct ICompressProgress { 131 SRes function(void *p, UInt64 inSize, UInt64 outSize) Progress; 132 /* Returns: result. (result != SZ_OK) means break. 133 Value (UInt64)(Int64)-1 for size means unknown value. */ 134 } 135 136 struct ISzAlloc { 137 void* function(void *p, size_t size) Alloc; 138 void function(void *p, void *address) Free; 139 } 140 141 void IAlloc_Alloc(ISzAlloc *p, size_t size) { p.Alloc(p, size); } 142 void IAlloc_Free(ISzAlloc *p, void *a) { p.Free(p, a); } 143