Imported Upstream version 9.20
[platform/upstream/7zip.git] / C / 7z.h
1 /* 7z.h -- 7z interface\r
2 2010-03-11 : Igor Pavlov : Public domain */\r
3 \r
4 #ifndef __7Z_H\r
5 #define __7Z_H\r
6 \r
7 #include "7zBuf.h"\r
8 \r
9 EXTERN_C_BEGIN\r
10 \r
11 #define k7zStartHeaderSize 0x20\r
12 #define k7zSignatureSize 6\r
13 extern Byte k7zSignature[k7zSignatureSize];\r
14 #define k7zMajorVersion 0\r
15 \r
16 enum EIdEnum\r
17 {\r
18   k7zIdEnd,\r
19   k7zIdHeader,\r
20   k7zIdArchiveProperties,\r
21   k7zIdAdditionalStreamsInfo,\r
22   k7zIdMainStreamsInfo,\r
23   k7zIdFilesInfo,\r
24   k7zIdPackInfo,\r
25   k7zIdUnpackInfo,\r
26   k7zIdSubStreamsInfo,\r
27   k7zIdSize,\r
28   k7zIdCRC,\r
29   k7zIdFolder,\r
30   k7zIdCodersUnpackSize,\r
31   k7zIdNumUnpackStream,\r
32   k7zIdEmptyStream,\r
33   k7zIdEmptyFile,\r
34   k7zIdAnti,\r
35   k7zIdName,\r
36   k7zIdCTime,\r
37   k7zIdATime,\r
38   k7zIdMTime,\r
39   k7zIdWinAttributes,\r
40   k7zIdComment,\r
41   k7zIdEncodedHeader,\r
42   k7zIdStartPos,\r
43   k7zIdDummy\r
44 };\r
45 \r
46 typedef struct\r
47 {\r
48   UInt32 NumInStreams;\r
49   UInt32 NumOutStreams;\r
50   UInt64 MethodID;\r
51   CBuf Props;\r
52 } CSzCoderInfo;\r
53 \r
54 void SzCoderInfo_Init(CSzCoderInfo *p);\r
55 void SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc);\r
56 \r
57 typedef struct\r
58 {\r
59   UInt32 InIndex;\r
60   UInt32 OutIndex;\r
61 } CSzBindPair;\r
62 \r
63 typedef struct\r
64 {\r
65   CSzCoderInfo *Coders;\r
66   CSzBindPair *BindPairs;\r
67   UInt32 *PackStreams;\r
68   UInt64 *UnpackSizes;\r
69   UInt32 NumCoders;\r
70   UInt32 NumBindPairs;\r
71   UInt32 NumPackStreams;\r
72   int UnpackCRCDefined;\r
73   UInt32 UnpackCRC;\r
74 \r
75   UInt32 NumUnpackStreams;\r
76 } CSzFolder;\r
77 \r
78 void SzFolder_Init(CSzFolder *p);\r
79 UInt64 SzFolder_GetUnpackSize(CSzFolder *p);\r
80 int SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);\r
81 UInt32 SzFolder_GetNumOutStreams(CSzFolder *p);\r
82 UInt64 SzFolder_GetUnpackSize(CSzFolder *p);\r
83 \r
84 SRes SzFolder_Decode(const CSzFolder *folder, const UInt64 *packSizes,\r
85     ILookInStream *stream, UInt64 startPos,\r
86     Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);\r
87 \r
88 typedef struct\r
89 {\r
90   UInt32 Low;\r
91   UInt32 High;\r
92 } CNtfsFileTime;\r
93 \r
94 typedef struct\r
95 {\r
96   CNtfsFileTime MTime;\r
97   UInt64 Size;\r
98   UInt32 Crc;\r
99   UInt32 Attrib;\r
100   Byte HasStream;\r
101   Byte IsDir;\r
102   Byte IsAnti;\r
103   Byte CrcDefined;\r
104   Byte MTimeDefined;\r
105   Byte AttribDefined;\r
106 } CSzFileItem;\r
107 \r
108 void SzFile_Init(CSzFileItem *p);\r
109 \r
110 typedef struct\r
111 {\r
112   UInt64 *PackSizes;\r
113   Byte *PackCRCsDefined;\r
114   UInt32 *PackCRCs;\r
115   CSzFolder *Folders;\r
116   CSzFileItem *Files;\r
117   UInt32 NumPackStreams;\r
118   UInt32 NumFolders;\r
119   UInt32 NumFiles;\r
120 } CSzAr;\r
121 \r
122 void SzAr_Init(CSzAr *p);\r
123 void SzAr_Free(CSzAr *p, ISzAlloc *alloc);\r
124 \r
125 \r
126 /*\r
127   SzExtract extracts file from archive\r
128 \r
129   *outBuffer must be 0 before first call for each new archive.\r
130 \r
131   Extracting cache:\r
132     If you need to decompress more than one file, you can send\r
133     these values from previous call:\r
134       *blockIndex,\r
135       *outBuffer,\r
136       *outBufferSize\r
137     You can consider "*outBuffer" as cache of solid block. If your archive is solid,\r
138     it will increase decompression speed.\r
139   \r
140     If you use external function, you can declare these 3 cache variables\r
141     (blockIndex, outBuffer, outBufferSize) as static in that external function.\r
142     \r
143     Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r
144 */\r
145 \r
146 typedef struct\r
147 {\r
148   CSzAr db;\r
149   \r
150   UInt64 startPosAfterHeader;\r
151   UInt64 dataPos;\r
152 \r
153   UInt32 *FolderStartPackStreamIndex;\r
154   UInt64 *PackStreamStartPositions;\r
155   UInt32 *FolderStartFileIndex;\r
156   UInt32 *FileIndexToFolderIndexMap;\r
157 \r
158   size_t *FileNameOffsets; /* in 2-byte steps */\r
159   CBuf FileNames;  /* UTF-16-LE */\r
160 } CSzArEx;\r
161 \r
162 void SzArEx_Init(CSzArEx *p);\r
163 void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);\r
164 UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);\r
165 int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);\r
166 \r
167 /*\r
168 if dest == NULL, the return value specifies the required size of the buffer,\r
169   in 16-bit characters, including the null-terminating character.\r
170 if dest != NULL, the return value specifies the number of 16-bit characters that\r
171   are written to the dest, including the null-terminating character. */\r
172 \r
173 size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest);\r
174 \r
175 SRes SzArEx_Extract(\r
176     const CSzArEx *db,\r
177     ILookInStream *inStream,\r
178     UInt32 fileIndex,         /* index of file */\r
179     UInt32 *blockIndex,       /* index of solid block */\r
180     Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r
181     size_t *outBufferSize,    /* buffer size for output buffer */\r
182     size_t *offset,           /* offset of stream for required file in *outBuffer */\r
183     size_t *outSizeProcessed, /* size of file in *outBuffer */\r
184     ISzAlloc *allocMain,\r
185     ISzAlloc *allocTemp);\r
186 \r
187 \r
188 /*\r
189 SzArEx_Open Errors:\r
190 SZ_ERROR_NO_ARCHIVE\r
191 SZ_ERROR_ARCHIVE\r
192 SZ_ERROR_UNSUPPORTED\r
193 SZ_ERROR_MEM\r
194 SZ_ERROR_CRC\r
195 SZ_ERROR_INPUT_EOF\r
196 SZ_ERROR_FAIL\r
197 */\r
198 \r
199 SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);\r
200 \r
201 EXTERN_C_END\r
202 \r
203 #endif\r