Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
5.4 KiB

  1. 7z ANSI-C Decoder 9.35
  2. ----------------------
  3. 7z ANSI-C provides 7z/LZMA decoding.
  4. 7z ANSI-C version is simplified version ported from C++ code.
  5. LZMA is default and general compression method of 7z format
  6. in 7-Zip compression program (www.7-zip.org). LZMA provides high
  7. compression ratio and very fast decompression.
  8. LICENSE
  9. -------
  10. 7z ANSI-C Decoder is part of the LZMA SDK.
  11. LZMA SDK is written and placed in the public domain by Igor Pavlov.
  12. Files
  13. ---------------------
  14. 7zDecode.* - Low level 7z decoding
  15. 7zExtract.* - High level 7z decoding
  16. 7zHeader.* - .7z format constants
  17. 7zIn.* - .7z archive opening
  18. 7zItem.* - .7z structures
  19. 7zMain.c - Test application
  20. How To Use
  21. ----------
  22. You can create .7z archive with 7z.exe, 7za.exe or 7zr.exe:
  23. 7z.exe a archive.7z *.htm -r -mx -m0fb=255
  24. If you have big number of files in archive, and you need fast extracting,
  25. you can use partly-solid archives:
  26. 7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K
  27. In that example 7-Zip will use 512KB solid blocks. So it needs to decompress only
  28. 512KB for extracting one file from such archive.
  29. Limitations of current version of 7z ANSI-C Decoder
  30. ---------------------------------------------------
  31. - It reads only "FileName", "Size", "LastWriteTime" and "CRC" information for each file in archive.
  32. - It supports only LZMA and Copy (no compression) methods with BCJ or BCJ2 filters.
  33. - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.
  34. These limitations will be fixed in future versions.
  35. Using 7z ANSI-C Decoder Test application:
  36. -----------------------------------------
  37. Usage: 7zDec <command> <archive_name>
  38. <Command>:
  39. e: Extract files from archive
  40. l: List contents of archive
  41. t: Test integrity of archive
  42. Example:
  43. 7zDec l archive.7z
  44. lists contents of archive.7z
  45. 7zDec e archive.7z
  46. extracts files from archive.7z to current folder.
  47. How to use .7z Decoder
  48. ----------------------
  49. Memory allocation
  50. ~~~~~~~~~~~~~~~~~
  51. 7z Decoder uses two memory pools:
  52. 1) Temporary pool
  53. 2) Main pool
  54. Such scheme can allow you to avoid fragmentation of allocated blocks.
  55. Steps for using 7z decoder
  56. --------------------------
  57. Use code at 7zMain.c as example.
  58. 1) Declare variables:
  59. inStream /* implements ILookInStream interface */
  60. CSzArEx db; /* 7z archive database structure */
  61. ISzAlloc allocImp; /* memory functions for main pool */
  62. ISzAlloc allocTempImp; /* memory functions for temporary pool */
  63. 2) call CrcGenerateTable(); function to initialize CRC structures.
  64. 3) call SzArEx_Init(&db); function to initialize db structures.
  65. 4) call SzArEx_Open(&db, inStream, &allocMain, &allocTemp) to open archive
  66. This function opens archive "inStream" and reads headers to "db".
  67. All items in "db" will be allocated with "allocMain" functions.
  68. SzArEx_Open function allocates and frees temporary structures by "allocTemp" functions.
  69. 5) List items or Extract items
  70. Listing code:
  71. ~~~~~~~~~~~~~
  72. Use SzArEx_GetFileNameUtf16 function. Look example code in C\Util\7z\7zMain.c file.
  73. Extracting code:
  74. ~~~~~~~~~~~~~~~~
  75. SZ_RESULT SzAr_Extract(
  76. CArchiveDatabaseEx *db,
  77. ILookInStream *inStream,
  78. UInt32 fileIndex, /* index of file */
  79. UInt32 *blockIndex, /* index of solid block */
  80. Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
  81. size_t *outBufferSize, /* buffer size for output buffer */
  82. size_t *offset, /* offset of stream for required file in *outBuffer */
  83. size_t *outSizeProcessed, /* size of file in *outBuffer */
  84. ISzAlloc *allocMain,
  85. ISzAlloc *allocTemp);
  86. If you need to decompress more than one file, you can send these values from previous call:
  87. blockIndex,
  88. outBuffer,
  89. outBufferSize,
  90. You can consider "outBuffer" as cache of solid block. If your archive is solid,
  91. it will increase decompression speed.
  92. After decompressing you must free "outBuffer":
  93. allocImp.Free(outBuffer);
  94. 6) call SzArEx_Free(&db, allocImp.Free) to free allocated items in "db".
  95. Memory requirements for .7z decoding
  96. ------------------------------------
  97. Memory usage for Archive opening:
  98. - Temporary pool:
  99. - Memory for uncompressed .7z headers
  100. - some other temporary blocks
  101. - Main pool:
  102. - Memory for database:
  103. Estimated size of one file structures in solid archive:
  104. - Size (4 or 8 Bytes)
  105. - CRC32 (4 bytes)
  106. - LastWriteTime (8 bytes)
  107. - Some file information (4 bytes)
  108. - File Name (variable length) + pointer + allocation structures
  109. Memory usage for archive Decompressing:
  110. - Temporary pool:
  111. - Memory for LZMA decompressing structures
  112. - Main pool:
  113. - Memory for decompressed solid block
  114. - Memory for temprorary buffers, if BCJ2 fileter is used. Usually these
  115. temprorary buffers can be about 15% of solid block size.
  116. 7z Decoder doesn't allocate memory for compressed blocks.
  117. Instead of this, you must allocate buffer with desired
  118. size before calling 7z Decoder. Use 7zMain.c as example.
  119. Defines
  120. -------
  121. _SZ_ALLOC_DEBUG - define it if you want to debug alloc/free operations to stderr.
  122. ---
  123. http://www.7-zip.org
  124. http://www.7-zip.org/sdk.html
  125. http://www.7-zip.org/support.html