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