7zC.txt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. 7z ANSI-C Decoder 4.48
  2. ----------------------
  3. 7z ANSI-C Decoder 4.48 Copyright (C) 1999-2006 Igor Pavlov
  4. 7z ANSI-C provides 7z/LZMA decoding.
  5. 7z ANSI-C version is simplified version ported from C++ code.
  6. LZMA is default and general compression method of 7z format
  7. in 7-Zip compression program (www.7-zip.org). LZMA provides high
  8. compression ratio and very fast decompression.
  9. LICENSE
  10. -------
  11. Read lzma.txt for information about license.
  12. Files
  13. ---------------------
  14. 7zAlloc.* - Allocate and Free
  15. 7zBuffer.* - Buffer structure
  16. 7zCrc.* - CRC32 code
  17. 7zDecode.* - Low level memory->memory decoding
  18. 7zExtract.* - High level stream->memory decoding
  19. 7zHeader.* - .7z format constants
  20. 7zIn.* - .7z archive opening
  21. 7zItem.* - .7z structures
  22. 7zMain.c - Test application
  23. 7zMethodID.* - MethodID structure
  24. 7zTypes.h - Base types and constants
  25. How To Use
  26. ----------
  27. You must download 7-Zip program from www.7-zip.org.
  28. You can create .7z archive with 7z.exe or 7za.exe:
  29. 7za.exe a archive.7z *.htm -r -mx -m0fb=255
  30. If you have big number of files in archive, and you need fast extracting,
  31. you can use partly-solid archives:
  32. 7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K
  33. In that example 7-Zip will use 512KB solid blocks. So it needs to decompress only
  34. 512KB for extracting one file from such archive.
  35. Limitations of current version of 7z ANSI-C Decoder
  36. ---------------------------------------------------
  37. - It reads only "FileName", "Size", "LastWriteTime" and "CRC" information for each file in archive.
  38. - It supports only LZMA and Copy (no compression) methods with BCJ or BCJ2 filters.
  39. - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.
  40. These limitations will be fixed in future versions.
  41. Using 7z ANSI-C Decoder Test application:
  42. -----------------------------------------
  43. Usage: 7zDec <command> <archive_name>
  44. <Command>:
  45. e: Extract files from archive
  46. l: List contents of archive
  47. t: Test integrity of archive
  48. Example:
  49. 7zDec l archive.7z
  50. lists contents of archive.7z
  51. 7zDec e archive.7z
  52. extracts files from archive.7z to current folder.
  53. How to use .7z Decoder
  54. ----------------------
  55. .7z Decoder can be compiled in one of two modes:
  56. 1) Default mode. In that mode 7z Decoder will read full compressed
  57. block to RAM before decompressing.
  58. 2) Mode with defined _LZMA_IN_CB. In that mode 7z Decoder can read
  59. compressed block by parts. And you can specify desired buffer size.
  60. So memory requirements can be reduced. But decompressing speed will
  61. be 5-10% lower and code size is slightly larger.
  62. Memory allocation
  63. ~~~~~~~~~~~~~~~~~
  64. 7z Decoder uses two memory pools:
  65. 1) Temporary pool
  66. 2) Main pool
  67. Such scheme can allow you to avoid fragmentation of allocated blocks.
  68. Steps for using 7z decoder
  69. --------------------------
  70. Use code at 7zMain.c as example.
  71. 1) Declare variables:
  72. inStream /* implements ISzInStream interface */
  73. CArchiveDatabaseEx db; /* 7z archive database structure */
  74. ISzAlloc allocImp; /* memory functions for main pool */
  75. ISzAlloc allocTempImp; /* memory functions for temporary pool */
  76. 2) call InitCrcTable(); function to initialize CRC structures.
  77. 3) call SzArDbExInit(&db); function to initialize db structures.
  78. 4) call SzArchiveOpen(inStream, &db, &allocMain, &allocTemp) to open archive
  79. This function opens archive "inStream" and reads headers to "db".
  80. All items in "db" will be allocated with "allocMain" functions.
  81. SzArchiveOpen function allocates and frees temporary structures by "allocTemp" functions.
  82. 5) List items or Extract items
  83. Listing code:
  84. ~~~~~~~~~~~~~
  85. {
  86. UInt32 i;
  87. for (i = 0; i < db.Database.NumFiles; i++)
  88. {
  89. CFileItem *f = db.Database.Files + i;
  90. printf("%10d %s\n", (int)f->Size, f->Name);
  91. }
  92. }
  93. Extracting code:
  94. ~~~~~~~~~~~~~~~~
  95. SZ_RESULT SzExtract(
  96. ISzInStream *inStream,
  97. CArchiveDatabaseEx *db,
  98. UInt32 fileIndex, /* index of file */
  99. UInt32 *blockIndex, /* index of solid block */
  100. Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
  101. size_t *outBufferSize, /* buffer size for output buffer */
  102. size_t *offset, /* offset of stream for required file in *outBuffer */
  103. size_t *outSizeProcessed, /* size of file in *outBuffer */
  104. ISzAlloc *allocMain,
  105. ISzAlloc *allocTemp);
  106. If you need to decompress more than one file, you can send these values from previous call:
  107. blockIndex,
  108. outBuffer,
  109. outBufferSize,
  110. You can consider "outBuffer" as cache of solid block. If your archive is solid,
  111. it will increase decompression speed.
  112. After decompressing you must free "outBuffer":
  113. allocImp.Free(outBuffer);
  114. 6) call SzArDbExFree(&db, allocImp.Free) to free allocated items in "db".
  115. Memory requirements for .7z decoding
  116. ------------------------------------
  117. Memory usage for Archive opening:
  118. - Temporary pool:
  119. - Memory for compressed .7z headers (if _LZMA_IN_CB is not defined)
  120. - Memory for uncompressed .7z headers
  121. - some other temporary blocks
  122. - Main pool:
  123. - Memory for database:
  124. Estimated size of one file structures in solid archive:
  125. - Size (4 or 8 Bytes)
  126. - CRC32 (4 bytes)
  127. - LastWriteTime (8 bytes)
  128. - Some file information (4 bytes)
  129. - File Name (variable length) + pointer + allocation structures
  130. Memory usage for archive Decompressing:
  131. - Temporary pool:
  132. - Memory for compressed solid block (if _LZMA_IN_CB is not defined)
  133. - Memory for LZMA decompressing structures
  134. - Main pool:
  135. - Memory for decompressed solid block
  136. - Memory for temprorary buffers, if BCJ2 fileter is used. Usually these
  137. temprorary buffers can be about 15% of solid block size.
  138. If _LZMA_IN_CB is defined, 7z Decoder will not allocate memory for
  139. compressed blocks. Instead of this, you must allocate buffer with desired
  140. size before calling 7z Decoder. Use 7zMain.c as example.
  141. EXIT codes
  142. -----------
  143. 7z Decoder functions can return one of the following codes:
  144. #define SZ_OK (0)
  145. #define SZE_DATA_ERROR (1)
  146. #define SZE_OUTOFMEMORY (2)
  147. #define SZE_CRC_ERROR (3)
  148. #define SZE_NOTIMPL (4)
  149. #define SZE_FAIL (5)
  150. #define SZE_ARCHIVE_ERROR (6)
  151. LZMA Defines
  152. ------------
  153. _LZMA_IN_CB - Use special callback mode for input stream to reduce memory requirements
  154. _SZ_FILE_SIZE_32 - define it if you need only support for files smaller than 4 GB
  155. _SZ_NO_INT_64 - define it if your compiler doesn't support long long int or __int64.
  156. _LZMA_PROB32 - it can increase LZMA decompressing speed on some 32-bit CPUs.
  157. _SZ_ALLOC_DEBUG - define it if you want to debug alloc/free operations to stderr.
  158. ---
  159. http://www.7-zip.org
  160. http://www.7-zip.org/support.html