This commit is contained in:
Igor Pavlov
2005-05-30 00:00:00 +00:00
committed by Kornel Lesiński
parent 8c1b5c7b7e
commit 3c510ba80b
926 changed files with 40559 additions and 23519 deletions

238
DOC/7zC.txt Executable file
View File

@@ -0,0 +1,238 @@
7z ANSI-C Decoder 4.16
----------------------
7z ANSI-C Decoder 4.16 Copyright (C) 1999-2005 Igor Pavlov
7z ANSI-C provides 7z/LZMA decoding.
7z ANSI-C version is simplified version ported from C++ code.
LZMA is default and general compression method of 7z format
in 7-Zip compression program (www.7-zip.org). LZMA provides high
compression ratio and very fast decompression.
LICENSE
-------
Read lzma.txt for informaton about license.
Files
---------------------
7zAlloc.* - Allocate and Free
7zBuffer.* - Buffer structure
7zCrc.* - CRC32 code
7zDecode.* - Low level memory->memory decoding
7zExtract.* - High level stream->memory decoding
7zHeader.* - .7z format constants
7zIn.* - .7z archive opening
7zItem.* - .7z structures
7zMain.c - Test application
7zMethodID.* - MethodID structure
7zTypes.h - Base types and constants
How To Use
----------
You must download 7-Zip program from www.7-zip.org.
You can create .7z archive with 7z.exe or 7za.exe:
7za.exe a archive.7z *.htm -r -mx -m0fb=255
If you have big number of files in archive, and you need fast extracting,
you can use partly-solid archives:
7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K
In that example 7-Zip will use 512KB solid blocks. So it needs to decompress only
512KB for extracting one file from such archive.
Limitations of current version of 7z ANSI-C Decoder
---------------------------------------------------
- It doesn't support separated "folder" items inside archive.
But you still can use files that are in subfolders
- It doesn't support empty files (size = 0) inside archive.
- It reads only "FileName", "Size", and "CRC" information for each file in archive.
- It supports only LZMA and Copy (no compression) methods.
- It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.
These limitations will be fixed in future versions.
Using 7z ANSI-C Decoder Test application:
-----------------------------------------
Usage: 7zDec <command> <archive_name>
<Command>:
e: Extract files from archive
l: List contents of archive
t: Test integrity of archive
Example:
7zDec l archive.7z
lists contents of archive.7z
7zDec e archive.7z
extracts files from archive.7z to current folder.
How to use .7z Decoder
----------------------
.7z Decoder can be compiled in one of two modes:
1) Default mode. In that mode 7z Decoder will read full compressed
block to RAM before decompressing.
2) Mode with defined _LZMA_IN_CB. In that mode 7z Decoder can read
compressed block by parts. And you can specify desired buffer size.
So memory requirements can be reduced. But decompressing speed will
be 5-10% lower and code size is slightly larger.
Memory allocation
~~~~~~~~~~~~~~~~~
7z Decoder uses two memory pools:
1) Temporary pool
2) Main pool
Such scheme can allow you to avoid fragmentation of alocated blocks.
Steps for using 7z decoder
--------------------------
Use code at 7zMain.c as example.
1) Declare variables:
inStream /* implements ISzInStream interface */
CArchiveDatabaseEx db; /* 7z archive database structure */
ISzAlloc allocImp; /* memory functions for main pool */
ISzAlloc allocTempImp; /* memory functions for temporary pool */
2) call InitCrcTable(); function to initialize CRC structures.
3) call SzArDbExInit(&db); function to initialize db structures.
4) call SzArchiveOpen(inStream, &db, &allocMain, &allocTemp) to open archive
This function opens archive "inStream" and reads headers to "db".
All items in "db" will be allocated with "allocMain" functions.
SzArchiveOpen function allocates and frees temporary structures by "allocTemp" functions.
5) List items or Extract items
Listing code:
~~~~~~~~~~~~~
{
UInt32 i;
for (i = 0; i < db.Database.NumFiles; i++)
{
CFileItem *f = db.Database.Files + i;
printf("%10d %s\n", (int)f->Size, f->Name);
}
}
Extracting code:
~~~~~~~~~~~~~~~~
SZ_RESULT SzExtract(
ISzInStream *inStream,
CArchiveDatabaseEx *db,
UInt32 fileIndex, /* index of file */
UInt32 *blockIndex, /* index of solid block */
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
size_t *outBufferSize, /* buffer size for output buffer */
size_t *offset, /* offset of stream for required file in *outBuffer */
size_t *outSizeProcessed, /* size of file in *outBuffer */
ISzAlloc *allocMain,
ISzAlloc *allocTemp);
If you need to decompress more than one file, you can send these values from preevious call:
blockIndex,
outBuffer,
outBufferSize,
You can consider "outBuffer" as cache of solid block. If your archive is solid,
it will increase decompression speed.
After decompressing you must free "outBuffer":
allocImp.Free(outBuffer);
6) call SzArDbExFree(&db, allocImp.Free) to free allocated items in "db".
Memory requirements for .7z decoding
------------------------------------
Memory usage for Archive openning:
- Temporary pool:
- Memory for compressed .7z headers (if _LZMA_IN_CB is not defined)
- Memory for uncompressed .7z headers
- some other temporary blocks
- Main pool:
- Memory for database:
Estimated size of one file structures in solid archive:
- Size (4 or 8 Bytes)
- CRC32 (4 bytes)
- Some file information (4 bytes)
- File Name (variable length) + pointer + allocation structures
Memory usage for archive Decompressing:
- Temporary pool:
- Memory for compressed solid block (if _LZMA_IN_CB is not defined)
- Memory for LZMA decompressing structures
- Main pool:
- Memory for decompressed solid block
If _LZMA_IN_CB is defined, 7z Decoder will not allocate memory for
compressed blocks. Instead of this, you must allocate buffer with desired
size before calling 7z Decoder. Use 7zMain.c as example.
EXIT codes
-----------
7z Decoder functions can return one of the following codes:
#define SZ_OK (0)
#define SZE_DATA_ERROR (1)
#define SZE_OUTOFMEMORY (2)
#define SZE_CRC_ERROR (3)
#define SZE_NOTIMPL (4)
#define SZE_FAIL (5)
#define SZE_ARCHIVE_ERROR (6)
LZMA Defines
------------
_LZMA_IN_CB - Use special callback mode for input stream to reduce memory requirements
_SZ_FILE_SIZE_64 - define it if you need support for files larger than 4 GB
_SZ_NO_INT_64 - define it if your compiler doesn't support long long int
_LZMA_PROB32 - it can increase LZMA decompressing speed on some 32-bit CPUs.
_SZ_ONE_DIRECTORY - define it if you want to locate all source files to one direcory
_SZ_ALLOC_DEBUG - define it if you want to debug alloc/free operations to stderr.
---
http://www.7-zip.org
http://www.7-zip.org/support.html

449
DOC/7zip.nsi Executable file
View File

@@ -0,0 +1,449 @@
;--------------------------------
;Defines
!define VERSION_MAJOR 4
!define VERSION_MINOR 20
!define VERSION_POSTFIX_FULL ""
!define NAME_FULL "7-Zip ${VERSION_MAJOR}.${VERSION_MINOR}${VERSION_POSTFIX_FULL}"
!define VERSION_POSTFIX ""
!define FM_LINK "7-Zip File Manager.lnk"
!define HELP_LINK "7-Zip Help.lnk"
!define CLSID_CONTEXT_MENU {23170F69-40C1-278A-1000-000100020000}
#!define NO_COMPRESSION
!include "Library.nsh"
!include "MUI.nsh"
;--------------------------------
;Configuration
;General
Name "${NAME_FULL}"
BrandingText "www.7-zip.org"
OutFile "..\7z${VERSION_MAJOR}${VERSION_MINOR}${VERSION_POSTFIX}.exe"
;Folder selection page
InstallDir "$PROGRAMFILES\7-Zip"
;Get install folder from registry if available
InstallDirRegKey HKLM "Software\7-Zip" "Path"
;Compressor
!ifndef NO_COMPRESSION
SetCompressor lzma
SetCompressorDictSize 4
!else
SetCompressor zlib
SetCompress off
!endif
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Pages
#!insertmacro MUI_PAGE_LICENSE "License.txt"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Reserve Files
;These files should be inserted before other files in the data block
;Keep these lines before any File command
;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA)
!insertmacro MUI_RESERVEFILE_LANGDLL
;--------------------------------
;Installer Sections
Section
# delete old unwanted files
Delete $INSTDIR\7zn.exe
Delete $INSTDIR\7zan.exe
Delete $INSTDIR\7zipDoc.txt
Delete $INSTDIR\Codecs\Implode.dll
# install files
SetOutPath "$INSTDIR"
File file_id.diz
File descript.ion
File History.txt
File License.txt
File copying.txt
File readme.txt
File 7zip_pad.xml
# File 7-zip.dll
# File 7-zipn.dll
File 7zFM.exe
File 7zFMn.exe
File 7z.exe
File 7za.exe
File 7zg.exe
File 7zgn.exe
File 7z.sfx
File 7zCon.sfx
File 7zC.sfx
File 7-zip.chm
SetOutPath $INSTDIR\Formats
File 7z.dll
File arj.dll
File bz2.dll
File cab.dll
File cpio.dll
File deb.dll
File gz.dll
File rar.dll
File rpm.dll
File split.dll
File tar.dll
File z.dll
File zip.dll
SetOutPath $INSTDIR\Codecs
File LZMA.dll
File Rar29.dll
File Deflate.dll
File Branch.dll
File Swap.dll
File Copy.dll
File PPMD.dll
File BZip2.dll
File AES.dll
File 7zAES.dll
SetOutPath $INSTDIR\Lang
File en.ttt
File af.txt
File ar.txt
File ast.txt
File az.txt
File be.txt
File bg.txt
File br.txt
File ca.txt
File cs.txt
File da.txt
File de.txt
File el.txt
File eo.txt
File es.txt
File et.txt
File fa.txt
File fi.txt
File fr.txt
File fur.txt
File fy.txt
File gl.txt
File he.txt
File hr.txt
File hu.txt
File id.txt
File it.txt
File ja.txt
File ka.txt
File ko.txt
File lt.txt
File lv.txt
File mk.txt
File mn.txt
File nl.txt
File no.txt
File pl.txt
File pt.txt
File pt-br.txt
File ro.txt
File ru.txt
File sk.txt
File sl.txt
File sr.txt
File sv.txt
File ta.txt
File th.txt
File tr.txt
File uk.txt
File uz.txt
File va.txt
File vi.txt
File vr.txt
File zh-cn.txt
File zh-tw.txt
SetOutPath $INSTDIR
# delete "current user" menu items
Delete "$SMPROGRAMS\7-Zip\${FM_LINK}"
Delete "$SMPROGRAMS\7-Zip\${HELP_LINK}"
RMDir "$SMPROGRAMS\7-Zip"
# set "all users" mode
SetShellVarContext all
StrCpy $0 0
System::Call "kernel32::GetVersion() i .r0"
IntCmpU $0 0x80000000 0 regNT 0
!insertmacro InstallLib REGDLL NOTSHARED REBOOT_NOTPROTECTED 7-zip.dll $INSTDIR\7-zip.dll $INSTDIR
File 7-Zipn.dll
Goto doneReg
regNT:
!insertmacro InstallLib REGDLL NOTSHARED REBOOT_NOTPROTECTED 7-zipn.dll $INSTDIR\7-zipn.dll $INSTDIR
File 7-Zip.dll
doneReg:
ClearErrors
# create start menu icons
SetOutPath $INSTDIR # working directory
CreateDirectory $SMPROGRAMS\7-Zip
StrCpy $1 "n"
IntCmpU $0 0x80000000 0 +2 0
StrCpy $1 ""
CreateShortcut "$SMPROGRAMS\7-Zip\${FM_LINK}" $INSTDIR\7zFM$1.exe
CreateShortcut "$SMPROGRAMS\7-Zip\${HELP_LINK}" $INSTDIR\7-zip.chm
IfErrors 0 noScErrors
SetShellVarContext current
CreateDirectory $SMPROGRAMS\7-Zip
CreateShortcut "$SMPROGRAMS\7-Zip\${FM_LINK}" $INSTDIR\7zFM$1.exe
CreateShortcut "$SMPROGRAMS\7-Zip\${HELP_LINK}" $INSTDIR\7-zip.chm
noScErrors:
# store install folder
WriteRegStr HKLM "Software\7-Zip" "Path" $INSTDIR
WriteRegStr HKCU "Software\7-Zip" "Path" $INSTDIR
# write reg entries
WriteRegStr HKCR "*\shellex\ContextMenuHandlers\7-Zip" "" "${CLSID_CONTEXT_MENU}"
WriteRegStr HKCR "Directory\shellex\ContextMenuHandlers\7-Zip" "" "${CLSID_CONTEXT_MENU}"
WriteRegStr HKCR "Folder\shellex\ContextMenuHandlers\7-Zip" "" "${CLSID_CONTEXT_MENU}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe" "" "$INSTDIR\7zFM.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe" "Path" "$INSTDIR"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\7zFMn.exe" "" "$INSTDIR\7zFMn.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\7zFMn.exe" "Path" "$INSTDIR"
# create uninstaller
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" "DisplayName" "${NAME_FULL}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" "UninstallString" '"$INSTDIR\Uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" "NoRepair" 1
WriteUninstaller $INSTDIR\Uninstall.exe
SectionEnd
;--------------------------------
;Installer Functions
/*
Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
*/
;--------------------------------
;Uninstaller Section
Section "Uninstall"
# delete files
Delete $INSTDIR\file_id.diz
Delete $INSTDIR\descript.ion
Delete $INSTDIR\History.txt
Delete $INSTDIR\License.txt
Delete $INSTDIR\copying.txt
Delete $INSTDIR\readme.txt
Delete $INSTDIR\7zip_pad.xml
Delete /REBOOTOK $INSTDIR\7-zip.dll
Delete /REBOOTOK $INSTDIR\7-zipn.dll
Delete $INSTDIR\7zFM.exe
Delete $INSTDIR\7zFMn.exe
Delete $INSTDIR\7z.exe
Delete $INSTDIR\7za.exe
Delete $INSTDIR\7zg.exe
Delete $INSTDIR\7zgn.exe
Delete $INSTDIR\7z.sfx
Delete $INSTDIR\7zCon.sfx
Delete $INSTDIR\7zC.sfx
Delete $INSTDIR\7-zip.chm
Delete $INSTDIR\Formats\7z.dll
Delete $INSTDIR\Formats\arj.dll
Delete $INSTDIR\Formats\bz2.dll
Delete $INSTDIR\Formats\cab.dll
Delete $INSTDIR\Formats\cpio.dll
Delete $INSTDIR\Formats\deb.dll
Delete $INSTDIR\Formats\gz.dll
Delete $INSTDIR\Formats\rar.dll
Delete $INSTDIR\Formats\rpm.dll
Delete $INSTDIR\Formats\split.dll
Delete $INSTDIR\Formats\tar.dll
Delete $INSTDIR\Formats\z.dll
Delete $INSTDIR\Formats\zip.dll
RMDir $INSTDIR\Formats
Delete $INSTDIR\Codecs\LZMA.dll
Delete $INSTDIR\Codecs\Rar29.dll
Delete $INSTDIR\Codecs\Deflate.dll
Delete $INSTDIR\Codecs\Branch.dll
Delete $INSTDIR\Codecs\Swap.dll
Delete $INSTDIR\Codecs\Copy.dll
Delete $INSTDIR\Codecs\PPMD.dll
Delete $INSTDIR\Codecs\BZip2.dll
Delete $INSTDIR\Codecs\AES.dll
Delete $INSTDIR\Codecs\7zAES.dll
RMDir $INSTDIR\Codecs
Delete $INSTDIR\Lang\en.ttt
Delete $INSTDIR\Lang\af.txt
Delete $INSTDIR\Lang\ar.txt
Delete $INSTDIR\Lang\ast.txt
Delete $INSTDIR\Lang\az.txt
Delete $INSTDIR\Lang\be.txt
Delete $INSTDIR\Lang\bg.txt
Delete $INSTDIR\Lang\br.txt
Delete $INSTDIR\Lang\ca.txt
Delete $INSTDIR\Lang\cs.txt
Delete $INSTDIR\Lang\da.txt
Delete $INSTDIR\Lang\de.txt
Delete $INSTDIR\Lang\el.txt
Delete $INSTDIR\Lang\eo.txt
Delete $INSTDIR\Lang\es.txt
Delete $INSTDIR\Lang\et.txt
Delete $INSTDIR\Lang\fa.txt
Delete $INSTDIR\Lang\fi.txt
Delete $INSTDIR\Lang\fr.txt
Delete $INSTDIR\Lang\fur.txt
Delete $INSTDIR\Lang\fy.txt
Delete $INSTDIR\Lang\gl.txt
Delete $INSTDIR\Lang\he.txt
Delete $INSTDIR\Lang\hr.txt
Delete $INSTDIR\Lang\hu.txt
Delete $INSTDIR\Lang\id.txt
Delete $INSTDIR\Lang\it.txt
Delete $INSTDIR\Lang\ja.txt
Delete $INSTDIR\Lang\ka.txt
Delete $INSTDIR\Lang\ko.txt
Delete $INSTDIR\Lang\lt.txt
Delete $INSTDIR\Lang\lv.txt
Delete $INSTDIR\Lang\mk.txt
Delete $INSTDIR\Lang\mn.txt
Delete $INSTDIR\Lang\nl.txt
Delete $INSTDIR\Lang\no.txt
Delete $INSTDIR\Lang\pl.txt
Delete $INSTDIR\Lang\pt.txt
Delete $INSTDIR\Lang\pt-br.txt
Delete $INSTDIR\Lang\ro.txt
Delete $INSTDIR\Lang\ru.txt
Delete $INSTDIR\Lang\sk.txt
Delete $INSTDIR\Lang\sl.txt
Delete $INSTDIR\Lang\sr.txt
Delete $INSTDIR\Lang\sv.txt
Delete $INSTDIR\Lang\ta.txt
Delete $INSTDIR\Lang\th.txt
Delete $INSTDIR\Lang\tr.txt
Delete $INSTDIR\Lang\uk.txt
Delete $INSTDIR\Lang\uz.txt
Delete $INSTDIR\Lang\va.txt
Delete $INSTDIR\Lang\vi.txt
Delete $INSTDIR\Lang\vr.txt
Delete $INSTDIR\Lang\zh-cn.txt
Delete $INSTDIR\Lang\zh-tw.txt
RMDir $INSTDIR\Lang
Delete $INSTDIR\Uninstall.exe
RMDir $INSTDIR
# delete start menu entires
SetShellVarContext all
# ClearErrors
Delete "$SMPROGRAMS\7-Zip\${FM_LINK}"
Delete "$SMPROGRAMS\7-Zip\${HELP_LINK}"
RMDir "$SMPROGRAMS\7-Zip"
# IfErrors 0 noScErrors
SetShellVarContext current
Delete "$SMPROGRAMS\7-Zip\${FM_LINK}"
Delete "$SMPROGRAMS\7-Zip\${HELP_LINK}"
RMDir "$SMPROGRAMS\7-Zip"
# noScErrors:
# delete registry entries
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\7zFMn.exe"
DeleteRegKey HKLM "Software\7-Zip"
DeleteRegKey HKCU "Software\7-Zip"
DeleteRegKey HKCR "CLSID\${CLSID_CONTEXT_MENU}"
DeleteRegKey HKCR "*\shellex\ContextMenuHandlers\7-Zip"
DeleteRegKey HKCR "Directory\shellex\ContextMenuHandlers\7-Zip"
DeleteRegKey HKCR "Folder\shellex\ContextMenuHandlers\7-Zip"
DeleteRegKey HKCR "7-Zip.001"
DeleteRegKey HKCR "7-Zip.7z"
DeleteRegKey HKCR "7-Zip.arj"
DeleteRegKey HKCR "7-Zip.bz2"
DeleteRegKey HKCR "7-Zip.cab"
DeleteRegKey HKCR "7-Zip.cpio"
DeleteRegKey HKCR "7-Zip.deb"
DeleteRegKey HKCR "7-Zip.gz"
DeleteRegKey HKCR "7-Zip.rar"
DeleteRegKey HKCR "7-Zip.rpm"
DeleteRegKey HKCR "7-Zip.split"
DeleteRegKey HKCR "7-Zip.tar"
DeleteRegKey HKCR "7-Zip.z"
DeleteRegKey HKCR "7-Zip.zip"
SectionEnd

View File

@@ -1,4 +1,4 @@
Compression method IDs (3.08 beta)
Compression method IDs (4.16 beta)
----------------------------------
Each compression method in 7z has unique binary value (ID).
@@ -35,7 +35,8 @@ List of defined IDs
05 - BC_M68_B (Big Endian)
07 - ARM Thumb
01 - BC_ARMThumb
08 - reserved for SPARC
08 - SPARC
05 - BC_SPARC
04 - PPMD
01 - Version
@@ -43,9 +44,12 @@ List of defined IDs
04 - Misc
00 - Reserved
01 - Zip
06 - Imploded
00 - Copy (not used). Use {00} instead
01 - Shrink
06 - Implode
08 - Deflate
09 - Deflate64
12 - BZip2 (not used). Use {04 02 02} instead
02 - BZip
02 - BZip2
03 - Rar

View File

@@ -1,6 +1,33 @@
Sources history of the 7-Zip
----------------------------
Version 4.19 beta 2005-05-21
--------------------------------------
- BZip2 code was rewritten. Now 7-Zip doesn't use original BZip2 code.
Old (original) version was moved to folder 7zip/Compress/BZip2Original/
Version 4.14 beta 2005-01-11
--------------------------------------
- STL using was reduced
- 7za now supports Split(001) archves
Version 4.10 beta 2004-10-21
--------------------------------------
- Codecs now use new interface: ICompressSetDecoderProperties2
Version 4.07 beta 2004-10-03
--------------------------------------
- some interfaces were changed slightly to support
-stdin -stdout mode.
- FilterCoder for simple filters
- Wildcard censor class was changed.
- Bug was fixed: when encrypted stream was multiple 16,
it used additional 16 empty bytes.
Version 3.11 2003-10-06
--------------------------------------
File functions support unicode strings even

544
DOC/lzma.txt Executable file
View File

@@ -0,0 +1,544 @@
LZMA SDK 4.17
-------------
LZMA SDK 4.17 Copyright (C) 1999-2005 Igor Pavlov
LZMA SDK provides developers with documentation, source code,
and sample code necessary to write software that uses LZMA compression.
LZMA is default and general compression method of 7z format
in 7-Zip compression program (www.7-zip.org). LZMA provides high
compression ratio and very fast decompression.
LZMA is an improved version of famous LZ77 compression algorithm.
It was improved in way of maximum increasing of compression ratio,
keeping high decompression speed and low memory requirements for
decompressing.
LICENSE
-------
LZMA SDK is licensed under two licenses:
1) GNU Lesser General Public License (GNU LGPL)
2) Common Public License (CPL)
It means that you can select one of these two licenses and
follow rules of that license.
SPECIAL EXCEPTION
Igor Pavlov, as the author of this code, expressly permits you
to statically or dynamically link your code (or bind by name)
to the files from LZMA SDK without subjecting your linked
code to the terms of the CPL or GNU LGPL.
Any modifications or additions to files from LZMA SDK, however,
are subject to the GNU LGPL or CPL terms.
SPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code,
while you keep LZMA SDK code unmodified.
SPECIAL EXCEPTION #2: Igor Pavlov, as the author of this code, expressly permits
you to use this code under the same terms and conditions contained in the License
Agreement you have for any previous version of LZMA SDK developed by Igor Pavlov.
SPECIAL EXCEPTION #2 allows owners of proprietary licenses to use latest version
of LZMA SDK as update for previous versions.
SPECIAL EXCEPTION #3: Igor Pavlov, as the author of this code, expressly permits
you to use code of examples (LzmaTest.c) as public domain code.
GNU LGPL and CPL licenses are pretty similar and both these
licenses are classified as
1) "Free software licenses" at http://www.gnu.org/
2) "OSI-approved" at http://www.opensource.org/
LZMA SDK also can be available under a proprietary license which
can include:
1) Right to modify code without subjecting modified code to the
terms of the CPL or GNU LGPL
2) Technical support for code
To request such proprietary license or any additional consultations,
send email message from that page:
http://www.7-zip.org/support.html
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You should have received a copy of the Common Public License
along with this library.
LZMA SDK Contents
-----------------
LZMA SDK includes:
- C++ source code of LZMA Encoder and Decoder
- C++ source code for file->file LZMA compressing and decompressing
- ANSI-C compatible source code for LZMA decompressing
- Compiled file->file LZMA compressing/decompressing program for Windows system
ANSI-C LZMA decompression code was ported from original C++ sources to C.
Also it was simplified and optimized for code size.
But it is fully compatible with LZMA from 7-Zip.
UNIX/Linux version
------------------
To compile C++ version of file->file LZMA, go to directory
SRC/7zip/Compress/LZMA_Alone
and type "make" or "make clean all" to recompile all.
In some UNIX/Linux versions you must compile LZMA with static libraries.
To compile with static libraries, change string in makefile
LIB = -lm
to string
LIB = -lm -static
Files
---------------------
SRC - directory with source code
lzma.txt - LZMA SDK description (this file)
7zFormat.txt - 7z Format description
7zC.txt - 7z ANSI-C Decoder description (this file)
methods.txt - Compression method IDs for .7z
LGPL.txt - GNU Lesser General Public License
CPL.html - Common Public License
lzma.exe - Compiled file->file LZMA encoder/decoder for Windows
history.txt - history of the LZMA SDK
Source code structure
---------------------
SRC
Common - common files for C++ projects
Windows - common files for Windows related code
7zip - files related to 7-Zip Project
Common - common files for 7-Zip
Compress - files related to compression/decompression
LZ - files related to LZ (Lempel-Ziv) compression algorithm
BinTree - Binary Tree Match Finder for LZ algorithm
HashChain - Hash Chain Match Finder for LZ algorithm
Patricia - Patricia Match Finder for LZ algorithm
RangeCoder - Range Coder (special code of compression/decompression)
LZMA - LZMA compression/decompression on C++
LZMA_Alone - file->file LZMA compression/decompression
LZMA_C - ANSI-C compatible LZMA decompressor
LzmaDecode.h - interface for LZMA decoding on ANSI-C
LzmaDecode.c - LZMA decoding on ANSI-C (new fastest version)
LzmaDecodeSize.c - LZMA decoding on ANSI-C (old size-optimized version)
LzmaTest.c - test application that decodes LZMA encoded file
Branch - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code
Archive - files related to archiving
7z_C - 7z ANSI-C Decoder
Source code of LZMA SDK is only part of big 7-Zip project. That is
why LZMA SDK uses such complex source code structure.
You can find ANSI-C LZMA decompressing code at folder
SRC/7zip/Compress/LZMA_C
7-Zip doesn't use that ANSI-C LZMA code and that code was developed
specially for this SDK. And files from LZMA_C do not need files from
other directories of SDK for compiling.
7-Zip source code can be downloaded from 7-Zip's SourceForge page:
http://sourceforge.net/projects/sevenzip/
LZMA Decompression features
---------------------------
- Variable dictionary size (up to 256 MB)
- Estimated compressing speed: about 500 KB/s on 1 GHz CPU
- Estimated decompressing speed:
- 8-12 MB/s on 1 GHz Intel Pentium 3 or AMD Athlon
- 500-1000 KB/s on 100 MHz ARM, MIPS, PowerPC or other simple RISC
- Small memory requirements for decompressing (8-32 KB + DictionarySize)
- Small code size for decompressing: 2-8 KB (depending from
speed optimizations)
LZMA decoder uses only integer operations and can be
implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).
Some critical operations that affect to speed of LZMA decompression:
1) 32*16 bit integer multiply
2) Misspredicted branches (penalty mostly depends from pipeline length)
3) 32-bit shift and arithmetic operations
Speed of LZMA decompression mostly depends from CPU speed.
Memory speed has no big meaning. But if your CPU has small data cache,
overall weight of memory speed will slightly increase.
How To Use
----------
Using LZMA encoder/decoder executable
--------------------------------------
Usage: LZMA <e|d> inputFile outputFile [<switches>...]
e: encode file
d: decode file
b: Benchmark. There are two tests: compressing and decompressing
with LZMA method. Benchmark shows rating in MIPS (million
instructions per second). Rating value is calculated from
measured speed and it is normalized with AMD Athlon XP CPU
results. Also Benchmark checks possible hardware errors (RAM
errors in most cases). Benchmark uses these settings:
(-a1, -d21, -fb32, -mfbt4). You can change only -d. Also you
can change number of iterations. Example for 30 iterations:
LZMA b 30
Default number of iterations is 10.
<Switches>
-a{N}: set compression mode 0 = fast, 1 = normal, 2 = max
default: 2 (max)
d{N}: Sets Dictionary size - [0, 28], default: 23 (8MB)
The maximum value for dictionary size is 256 MB = 2^28 bytes.
Dictionary size is calculated as DictionarySize = 2^N bytes.
For decompressing file compressed by LZMA method with dictionary
size D = 2^N you need about D bytes of memory (RAM).
-fb{N}: set number of fast bytes - [5, 255], default: 128
Usually big number gives a little bit better compression ratio
and slower compression process.
-lc{N}: set number of literal context bits - [0, 8], default: 3
Sometimes lc=4 gives gain for big files.
-lp{N}: set number of literal pos bits - [0, 4], default: 0
lp switch is intended for periodical data when period is
equal 2^N. For example, for 32-bit (4 bytes)
periodical data you can use lp=2. Often it's better to set lc0,
if you change lp switch.
-pb{N}: set number of pos bits - [0, 4], default: 2
pb switch is intended for periodical data
when period is equal 2^N.
-mf{MF_ID}: set Match Finder. Default: bt4.
Compression ratio for all bt* and pat* almost the same.
Algorithms from hc* group doesn't provide good compression
ratio, but they often works pretty fast in combination with
fast mode (-a0). Methods from bt* group require less memory
than methods from pat* group. Usually bt4 works faster than
any pat*, but for some types of files pat* can work faster.
Memory requirements depend from dictionary size
(parameter "d" in table below).
MF_ID Memory Description
bt2 d*9.5 + 1MB Binary Tree with 2 bytes hashing.
bt3 d*9.5 + 65MB Binary Tree with 2-3(full) bytes hashing.
bt4 d*9.5 + 6MB Binary Tree with 2-3-4 bytes hashing.
bt4b d*9.5 + 34MB Binary Tree with 2-3-4(big) bytes hashing.
pat2r d*26 + 1MB Patricia Tree with 2-bits nodes, removing.
pat2 d*38 + 1MB Patricia Tree with 2-bits nodes.
pat2h d*38 + 77MB Patricia Tree with 2-bits nodes, 2-3 bytes hashing.
pat3h d*62 + 85MB Patricia Tree with 3-bits nodes, 2-3 bytes hashing.
pat4h d*110 +101MB Patricia Tree with 4-bits nodes, 2-3 bytes hashing.
hc3 d*5.5 + 1MB Hash Chain with 2-3 bytes hashing.
hc4 d*5.5 + 6MB Hash Chain with 2-3-4 bytes hashing.
-eos: write End Of Stream marker. By default LZMA doesn't write
eos marker, since LZMA decoder knows uncompressed size
stored in .lzma file header.
-si: Read data from stdin (it will write End Of Stream marker).
-so: Write data to stdout
Examples:
1) LZMA e file.bin file.lzma -d16 -lc0
compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)
and 0 literal context bits. -lc0 allows to reduce memory requirements
for decompression.
2) LZMA e file.bin file.lzma -lc0 -lp2
compresses file.bin to file.lzma with settings suitable
for 32-bit periodical data (for example, ARM or MIPS code).
3) LZMA d file.lzma file.bin
decompresses file.lzma to file.bin.
Compression ratio hints
-----------------------
Recommendations
---------------
To increase compression ratio for LZMA compressing it's desirable
to have aligned data (if it's possible) and also it's desirable to locate
data in such order, where code is grouped in one place and data is
grouped in other place (it's better than such mixing: code, data, code,
data, ...).
Using Filters
-------------
You can increase compression ratio for some data types, using
special filters before compressing. For example, it's possible to
increase compression ratio on 5-10% for code for those CPU ISAs:
x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.
You can find C/C++ source code of such filters in folder "7zip/Compress/Branch"
You can check compression ratio gain of these filters with such
7-Zip commands (example for ARM code):
No filter:
7z a a1.7z a.bin -m0=lzma
With filter for little-endian ARM code:
7z a a2.7z a.bin -m0=bc_arm -m1=lzma
With filter for big-endian ARM code (using additional Swap4 filter):
7z a a3.7z a.bin -m0=swap4 -m1=bc_arm -m2=lzma
It works in such manner:
Compressing = Filter_encoding + LZMA_encoding
Decompressing = LZMA_decoding + Filter_decoding
Compressing and decompressing speed of such filters is very high,
so it will not increase decompressing time too much.
Moreover, it reduces decompression time for LZMA_decoding,
since compression ratio with filtering is higher.
These filters convert CALL (calling procedure) instructions
from relative offsets to absolute addresses, so such data becomes more
compressible. Source code of these CALL filters is pretty simple
(about 20 lines of C++), so you can convert it from C++ version yourself.
For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.
LZMA compressed file format
---------------------------
Offset Size Description
0 1 Special LZMA properties for compressed data
1 4 Dictionary size (little endian)
5 8 Uncompressed size (little endian). -1 means unknown size
13 Compressed data
ANSI-C LZMA Decoder
~~~~~~~~~~~~~~~~~~~
To use ANSI-C LZMA Decoder you need to files:
LzmaDecode.h and one of the following two files:
1) LzmaDecode.c - LZMA decoding on ANSI-C (new fastest version)
2) LzmaDecodeSize.c - LZMA decoding on ANSI-C (old size-optimized version)
use LzmaDecode.c, if you need fastest code.
Memory requirements for LZMA decoding
-------------------------------------
LZMA decoder doesn't allocate memory itself, so you must
calculate required memory, allocate it and send it to LZMA.
Stack usage of LZMA function for local variables is not
larger than 200 bytes.
Memory requirements for decompression depend
from interface that you want to use:
a) Memory to memory decompression:
M1 = (inputSize + outputSize + lzmaInternalSize).
b) Decompression with buffering:
M2 = (inputBufferSize + outputBufferSize + dictionarySize + lzmaInternalSize)
How To decompress data
----------------------
1) Read first byte of properties for LZMA compressed stream,
check that it has correct value and calculate three
LZMA property variables:
int lc, lp, pb;
unsigned char prop0 = properties[0];
if (prop0 >= (9*5*5))
{
sprintf(rs + strlen(rs), "\n properties error");
return 1;
}
for (pb = 0; prop0 >= (9 * 5);
pb++, prop0 -= (9 * 5));
for (lp = 0; prop0 >= 9;
lp++, prop0 -= 9);
lc = prop0;
2) Calculate required amount for LZMA lzmaInternalSize:
lzmaInternalSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp))) *
sizeof(CProb)
LZMA_BASE_SIZE = 1846
LZMA_LIT_SIZE = 768
LZMA decoder uses array of CProb variables as internal structure.
By default, CProb is (unsigned short)
But you can define _LZMA_PROB32 to make it (unsigned int)
It can increase speed on some 32-bit CPUs, but memory usage will
be doubled in that case.
2b) If you use Decompression with buffering, add 100 bytes to
lzmaInternalSize:
#ifdef _LZMA_OUT_READ
lzmaInternalSize += 100;
#endif
3) Allocate that memory with malloc or some other function:
lzmaInternalData = malloc(lzmaInternalSize);
4) Decompress data:
4a) If you use simple memory to memory decompression:
int result = LzmaDecode(lzmaInternalData, lzmaInternalSize,
lc, lp, pb,
unsigned char *inStream, unsigned int inSize,
unsigned char *outStream, unsigned int outSize,
&outSizeProcessed);
4b) If you use Decompression with buffering
4.1) Read dictionary size from properties
unsigned int dictionarySize = 0;
int i;
for (i = 0; i < 4; i++)
dictionarySize += (unsigned int)(b) << (i * 8);
4.2) Allocate memory for dictionary
unsigned char *dictionary = malloc(dictionarySize);
4.3) Initialize LZMA decoder:
LzmaDecoderInit((unsigned char *)lzmaInternalData, lzmaInternalSize,
lc, lp, pb,
dictionary, dictionarySize,
&bo.ReadCallback);
4.4) In loop call LzmaDecoderCode function:
for (nowPos = 0; nowPos < outSize;)
{
unsigned int blockSize = outSize - nowPos;
unsigned int kBlockSize = 0x10000;
if (blockSize > kBlockSize)
blockSize = kBlockSize;
res = LzmaDecode((unsigned char *)lzmaInternalData,
((unsigned char *)outStream) + nowPos, blockSize, &outSizeProcessed);
if (res != 0)
{
printf("\nerror = %d\n", res);
break;
}
nowPos += outSizeProcessed;
if (outSizeProcessed == 0)
{
outSize = nowPos;
break;
}
}
EXIT codes
-----------
LZMA decoder can return one of the following codes:
#define LZMA_RESULT_OK 0
#define LZMA_RESULT_DATA_ERROR 1
#define LZMA_RESULT_NOT_ENOUGH_MEM 2
If you use callback function for input data and you return some
error code, LZMA Decoder also returns that code.
LZMA Defines
------------
_LZMA_IN_CB - Use callback for input data
_LZMA_OUT_READ - Use read function for output data
_LZMA_LOC_OPT - Enable local speed optimizations inside code.
_LZMA_LOC_OPT is only for LzmaDecodeSize.c (size-optimized version).
_LZMA_LOC_OPT doesn't affect LzmaDecode.c (speed-optimized version)
_LZMA_PROB32 - It can increase speed on some 32-bit CPUs,
but memory usage will be doubled in that case
_LZMA_UINT32_IS_ULONG - Define it if int is 16-bit on your compiler
and long is 32-bit.
NOTES
-----
1) please note that LzmaTest.c doesn't free allocated memory in some cases.
But in your real applicaions you must free memory after decompression.
2) All numbers above were calculated for case when int is not more than
32-bit in your compiler. If in your compiler int is 64-bit or larger
probably LZMA can require more memory for some structures.
C++ LZMA Encoder/Decoder
~~~~~~~~~~~~~~~~~~~~~~~~
C++ LZMA code use COM-like interfaces. So if you want to use it,
you can study basics of COM/OLE.
By default, LZMA Encoder contains all Match Finders.
But for compressing it's enough to have just one of them.
So for reducing size of compressing code you can define:
#define COMPRESS_MF_BT
#define COMPRESS_MF_BT4
and it will use only bt4 match finder.
---
http://www.7-zip.org
http://www.7-zip.org/support.html

View File

@@ -1,9 +1,9 @@
7-Zip 3.11 Sources
7-Zip 4.20 Sources
------------------
7-Zip is a file archiver for Windows 95/98/ME/NT/2000/XP.
7-Zip is a file archiver for Windows 95/98/ME/NT/2000/2003/XP.
7-Zip Copyright (C) 1999-2003 Igor Pavlov.
7-Zip Copyright (C) 1999-2005 Igor Pavlov.
License Info
@@ -27,14 +27,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
License notes
-------------
You can support development of 7-Zip by registering and
paying $20. As registered user, you will be able
to get technical support via e-mail support@7-zip.org.
You can support development of 7-Zip by registering.
7-Zip is free software distributed under the GNU LGPL.
If you need license with other conditions, write to support@7-zip.org.
You also can request for help in creating code based on
7-Zip's code for your custom application.
If you need license with other conditions, write to
http://www.7-zip.org/support.html
---
Also this package contains files from LZMA SDK
you can download LZMA SDK from this page:
http://www.7-zip.org/sdk.html
read about license for LZMA SDk in file
DOC/lzma.txt
How to compile
@@ -44,8 +48,29 @@ For compiling some files you also need
new Platform SDK from Microsoft' Site:
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm
or
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/XPSP2FULLInstall.htm
or
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
If you use MSVC6, specify SDK directories at top of directories lists:
Tools / Options / Directories
- Include files
- Library files
Also if you want to compile Original BZip2 code you must
download BZip source to folder
7zip/Compress/BZip2Original/Original
You can find BZip2 sources from that page:
http://sources.redhat.com/bzip2/index.html
Compiling under Unix/Linux
--------------------------
If sizeof(wchar_t) == 4 in your compiler,
you must use only 2 low bytes of wchar_t.
Notes:
------
@@ -72,16 +97,12 @@ DOC Documentation
history.txt - Sources history
Methods.txt - Compression method IDs
readme.txt - Readme file
Alien Must contains third party sources
Compress
BZip2 BZip2 compression sources from
http://sources.redhat.com/bzip2/index.html
lzma.txt - LZMA SDK description
7zip.nsi - installer script for NSIS
Common Common modules
Windows Win32 wrappers
Far FAR interface wrappers
7zip
-------
@@ -153,7 +174,6 @@ Far FAR interface wrappers
---
Igor Pavlov
http://www.7-zip.org
support@7-zip.org
---