7z.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* 7z.h -- 7z interface
  2. 2017-04-03 : Igor Pavlov : Public domain */
  3. #ifndef __7Z_H
  4. #define __7Z_H
  5. #include "7zTypes.h"
  6. EXTERN_C_BEGIN
  7. #define k7zStartHeaderSize 0x20
  8. #define k7zSignatureSize 6
  9. extern const Byte k7zSignature[k7zSignatureSize];
  10. typedef struct
  11. {
  12. const Byte *Data;
  13. size_t Size;
  14. } CSzData;
  15. /* CSzCoderInfo & CSzFolder support only default methods */
  16. typedef struct
  17. {
  18. size_t PropsOffset;
  19. UInt32 MethodID;
  20. Byte NumStreams;
  21. Byte PropsSize;
  22. } CSzCoderInfo;
  23. typedef struct
  24. {
  25. UInt32 InIndex;
  26. UInt32 OutIndex;
  27. } CSzBond;
  28. #define SZ_NUM_CODERS_IN_FOLDER_MAX 4
  29. #define SZ_NUM_BONDS_IN_FOLDER_MAX 3
  30. #define SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX 4
  31. typedef struct
  32. {
  33. UInt32 NumCoders;
  34. UInt32 NumBonds;
  35. UInt32 NumPackStreams;
  36. UInt32 UnpackStream;
  37. UInt32 PackStreams[SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX];
  38. CSzBond Bonds[SZ_NUM_BONDS_IN_FOLDER_MAX];
  39. CSzCoderInfo Coders[SZ_NUM_CODERS_IN_FOLDER_MAX];
  40. } CSzFolder;
  41. SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd);
  42. typedef struct
  43. {
  44. UInt32 Low;
  45. UInt32 High;
  46. } CNtfsFileTime;
  47. typedef struct
  48. {
  49. Byte *Defs; /* MSB 0 bit numbering */
  50. UInt32 *Vals;
  51. } CSzBitUi32s;
  52. typedef struct
  53. {
  54. Byte *Defs; /* MSB 0 bit numbering */
  55. // UInt64 *Vals;
  56. CNtfsFileTime *Vals;
  57. } CSzBitUi64s;
  58. #define SzBitArray_Check(p, i) (((p)[(i) >> 3] & (0x80 >> ((i) & 7))) != 0)
  59. #define SzBitWithVals_Check(p, i) ((p)->Defs && ((p)->Defs[(i) >> 3] & (0x80 >> ((i) & 7))) != 0)
  60. typedef struct
  61. {
  62. UInt32 NumPackStreams;
  63. UInt32 NumFolders;
  64. UInt64 *PackPositions; // NumPackStreams + 1
  65. CSzBitUi32s FolderCRCs; // NumFolders
  66. size_t *FoCodersOffsets; // NumFolders + 1
  67. UInt32 *FoStartPackStreamIndex; // NumFolders + 1
  68. UInt32 *FoToCoderUnpackSizes; // NumFolders + 1
  69. Byte *FoToMainUnpackSizeIndex; // NumFolders
  70. UInt64 *CoderUnpackSizes; // for all coders in all folders
  71. Byte *CodersData;
  72. } CSzAr;
  73. UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex);
  74. SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,
  75. ILookInStream *stream, UInt64 startPos,
  76. Byte *outBuffer, size_t outSize,
  77. ISzAllocPtr allocMain);
  78. typedef struct
  79. {
  80. CSzAr db;
  81. UInt64 startPosAfterHeader;
  82. UInt64 dataPos;
  83. UInt32 NumFiles;
  84. UInt64 *UnpackPositions; // NumFiles + 1
  85. // Byte *IsEmptyFiles;
  86. Byte *IsDirs;
  87. CSzBitUi32s CRCs;
  88. CSzBitUi32s Attribs;
  89. // CSzBitUi32s Parents;
  90. CSzBitUi64s MTime;
  91. CSzBitUi64s CTime;
  92. UInt32 *FolderToFile; // NumFolders + 1
  93. UInt32 *FileToFolder; // NumFiles
  94. size_t *FileNameOffsets; /* in 2-byte steps */
  95. Byte *FileNames; /* UTF-16-LE */
  96. } CSzArEx;
  97. #define SzArEx_IsDir(p, i) (SzBitArray_Check((p)->IsDirs, i))
  98. #define SzArEx_GetFileSize(p, i) ((p)->UnpackPositions[(i) + 1] - (p)->UnpackPositions[i])
  99. void SzArEx_Init(CSzArEx *p);
  100. void SzArEx_Free(CSzArEx *p, ISzAllocPtr alloc);
  101. UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
  102. int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);
  103. /*
  104. if dest == NULL, the return value specifies the required size of the buffer,
  105. in 16-bit characters, including the null-terminating character.
  106. if dest != NULL, the return value specifies the number of 16-bit characters that
  107. are written to the dest, including the null-terminating character. */
  108. size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest);
  109. /*
  110. size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex);
  111. UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest);
  112. */
  113. /*
  114. SzArEx_Extract extracts file from archive
  115. *outBuffer must be 0 before first call for each new archive.
  116. Extracting cache:
  117. If you need to decompress more than one file, you can send
  118. these values from previous call:
  119. *blockIndex,
  120. *outBuffer,
  121. *outBufferSize
  122. You can consider "*outBuffer" as cache of solid block. If your archive is solid,
  123. it will increase decompression speed.
  124. If you use external function, you can declare these 3 cache variables
  125. (blockIndex, outBuffer, outBufferSize) as static in that external function.
  126. Free *outBuffer and set *outBuffer to 0, if you want to flush cache.
  127. */
  128. SRes SzArEx_Extract(
  129. const CSzArEx *db,
  130. ILookInStream *inStream,
  131. UInt32 fileIndex, /* index of file */
  132. UInt32 *blockIndex, /* index of solid block */
  133. Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
  134. size_t *outBufferSize, /* buffer size for output buffer */
  135. size_t *offset, /* offset of stream for required file in *outBuffer */
  136. size_t *outSizeProcessed, /* size of file in *outBuffer */
  137. ISzAllocPtr allocMain,
  138. ISzAllocPtr allocTemp);
  139. /*
  140. SzArEx_Open Errors:
  141. SZ_ERROR_NO_ARCHIVE
  142. SZ_ERROR_ARCHIVE
  143. SZ_ERROR_UNSUPPORTED
  144. SZ_ERROR_MEM
  145. SZ_ERROR_CRC
  146. SZ_ERROR_INPUT_EOF
  147. SZ_ERROR_FAIL
  148. */
  149. SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream,
  150. ISzAllocPtr allocMain, ISzAllocPtr allocTemp);
  151. EXTERN_C_END
  152. #endif