### Setup Input/Output Streams (C) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt Sets up the input and output streams for LZMA compression/decompression using custom file stream structures. The function pointers in the stream structures are assigned to custom read/write functions. ```C CFileSeqInStream inStream; CFileSeqOutStream outStream; inStream.funcTable.Read = MyRead; inStream.file = inFile; outStream.funcTable.Write = MyWrite; outStream.file = outFile; ``` -------------------------------- ### Memory Allocator Example in C Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt This code snippet demonstrates how to define custom memory allocation and deallocation functions for use with the LZMA decoder. It uses `malloc` and `free` from the standard C library and defines an `ISzAlloc` structure to hold the function pointers. The `p = p;` statements are used to disable compiler warnings about unused parameters. ```C void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); } void SzFree(void *p, void *address) { p = p; free(address); } ISzAlloc alloc = { SzAlloc, SzFree }; ``` -------------------------------- ### Fixing LZMA Compression Ratio Bug in C++ Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This code snippet shows the fix for a bug in LZMAEncoder.cpp that could lead to a decreased compression ratio when a block needs to move. The original code incremented the data pointer, while the corrected version uses the _matchFinder object to get the correct pointer. ```C++ data++ ``` ```C++ data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1; ``` -------------------------------- ### LGPL License Notice Template Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/copying.txt This is a template for the LGPL license notice to be included at the beginning of each source file. It includes the library name, copyright information, licensing terms, warranty disclaimer, and instructions on how to obtain a copy of the license. ```txt Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ``` -------------------------------- ### Compiling 7-Zip for arm64 with assembler Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/readme.txt Compiles 7-Zip for the arm64 architecture with assembler code. It uses the cmpl_gcc_arm64.mak file. ```makefile make -j -f ../../cmpl_gcc_arm64.mak ``` -------------------------------- ### Compiling 7-Zip for arm64 for macOS Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/readme.txt Compiles 7-Zip for the arm64 architecture specifically for macOS. It uses the cmpl_mac_arm64.mak file. ```makefile make -j -f ../../cmpl_mac_arm64.mak ``` -------------------------------- ### Compiling 7-Zip with CLANG (no assembler) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/readme.txt Compiles 7-Zip using CLANG without assembler code. It uses the cmpl_clang.mak file and requires changing the current directory. ```makefile cd CPP/7zip/Bundles/Alone2 make -j -f ../../cmpl_clang.mak ``` -------------------------------- ### Initialize and Decode LZMA Stream (C) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt Initializes the LZMA decoder state and then decodes the LZMA stream in a loop. The loop continues until the entire stream is decoded. LzmaDec_DecodeToBuf decodes a portion of the stream. ```C LzmaDec_Init(&state); for (;;) { ... int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode); ... } ``` -------------------------------- ### Initialize LZMA Encoder Properties (C) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt Initializes the LZMA encoder properties structure with default values. This structure can then be modified to customize the compression settings. ```C LzmaEncProps_Init(&props); ``` -------------------------------- ### Compiling 7-Zip with makefile Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/readme.txt Compiles 7-Zip using the makefile.gcc file, which is used for compiling Linux/macOS versions of 7-Zip with the make command. It requires changing the current directory to the location of the makefile.gcc file. ```makefile cd CPP/7zip/Bundles/Alone2 make -j -f makefile.gcc ``` -------------------------------- ### Generating Random 8-Byte Method ID Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/Methods.txt This code shows how to generate a random 8-byte method ID for use in 7-Zip archives. It includes a prefix, a developer ID, and a method ID. ```none 3F ZZ ZZ ZZ ZZ ZZ MM MM ``` -------------------------------- ### Compiling 7-Zip with GCC (no assembler) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/readme.txt Compiles 7-Zip using GCC without assembler code. It uses the cmpl_gcc.mak file and requires changing the current directory to the appropriate location. ```makefile cd CPP/7zip/Bundles/Alone2 make -j -f ../../cmpl_gcc.mak ``` -------------------------------- ### Compiling 7-Zip for x86-64 with asmc assembler Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/readme.txt Compiles 7-Zip for the x86-64 architecture using the asmc assembler. It uses the cmpl_gcc_x64.mak file. ```makefile make -j -f ../../cmpl_gcc_x64.mak ``` -------------------------------- ### Encode Data with LZMA (C) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt Encodes the input data using the LZMA algorithm. This function takes the encoder handle, input and output stream function tables, a progress callback, and allocators as parameters. ```C res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, NULL, &g_Alloc, &g_Alloc); ``` -------------------------------- ### Multi-call LZMA Decompression Allocation in C Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt This code snippet demonstrates how to allocate the CLzmaDec structures (state + dictionary) using the LZMA properties read from the header. It initializes the state using LzmaDec_Constr and then allocates the memory using LzmaDec_Allocate, passing the header, its size, and the memory allocator. ```C CLzmaDec state; LzmaDec_Constr(&state); res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc); if (res != SZ_OK) ``` -------------------------------- ### Copyright Disclaimer Sample Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/copying.txt This is a sample copyright disclaimer that can be used by an employer or school to disclaim copyright interest in the library. It includes the name of the organization, the name of the library, the author's name, and a signature. ```txt Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice ``` -------------------------------- ### Handling Anti-File Property in 7z FilesInfo Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/7zFormat.txt This code snippet handles the kAnti property within the 7z FilesInfo section. It iterates through EmptyStreams and reads a bit indicating whether the file is an anti-file. ```c++ kAnti: (0x10) for(EmptyStreams) BIT IsAntiFile ``` -------------------------------- ### Handling Empty File Property in 7z FilesInfo Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/7zFormat.txt This code snippet handles the kEmptyFile property within the 7z FilesInfo section. It iterates through EmptyStreams and reads a bit indicating whether the file is empty. ```c++ kEmptyFile: (0x0F) for(EmptyStreams) BIT IsEmptyFile ``` -------------------------------- ### Create LZMA Encoder Handle (C) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt Creates an LZMA encoder handle using the provided allocator. The handle is used for subsequent LZMA encoding operations. Returns an error if memory allocation fails. ```C CLzmaEncHandle enc; enc = LzmaEnc_Create(&g_Alloc); if (enc == 0) return SZ_ERROR_MEM; ``` -------------------------------- ### Single-Call LZMA Decompression Interface in C Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt This code snippet describes the interface for the single-call LZMA decompression function, `LzmaDecode`. It details the input parameters (compressed data, properties, sizes, allocator) and output parameters (decompressed data, processed sizes, status). It also lists the possible return values and their meanings, including success and various error conditions. ```C int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc); ``` -------------------------------- ### Handling Names Property in 7z FilesInfo Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/7zFormat.txt This code snippet handles the kNames property within the 7z FilesInfo section. It checks for external data and reads file names. ```c++ kNames: (0x11) BYTE External; if(External != 0) UINT64 DataIndex [] for(Files) { wchar_t Names[NameSize]; wchar_t 0; } [] ``` -------------------------------- ### Handling Time Properties (CTime, ATime, MTime) in 7z FilesInfo Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/7zFormat.txt This code snippet handles the kCTime, kATime, and kMTime properties within the 7z FilesInfo section. It checks if all times are defined and reads time values for defined items. ```c++ case kCTime: (0x12) case kATime: (0x13) case kMTime: (0x14) BYTE AllAreDefined if (AllAreDefined == 0) { for(NumFiles) BIT TimeDefined } BYTE External; if(External != 0) UINT64 DataIndex [] for(Definded Items) REAL_UINT64 Time [] ``` -------------------------------- ### SHA-1/SHA-256 Optimized Code Support Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt Adds support for optimized SHA-1 and SHA-256 code implementations. The optimized code is located in Sha1Opt.c, Sha256Opt.c, Sha256Opt.asm, and Sha1Opt.asm. ```Assembly Sha1Opt.c, Sha256Opt.c, Sha256Opt.asm, Sha1Opt.asm ``` -------------------------------- ### Handling Empty Stream Property in 7z FilesInfo Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/7zFormat.txt This code snippet handles the kEmptyStream property within the 7z FilesInfo section. It iterates through NumFiles and reads a bit indicating whether the stream is empty. ```c++ kEmptyStream: (0x0E) for(NumFiles) BIT IsEmptyStream ``` -------------------------------- ### 7z Decoder Variable Declarations Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/7zC.txt Declaration of variables required for using the 7z decoder. These variables include input stream, archive database, and memory allocation functions for both main and temporary pools. ```C inStream /* implements ILookInStream interface */ CSzArEx db; /* 7z archive database structure */ ISzAlloc allocImp; /* memory functions for main pool */ ISzAlloc allocTempImp; /* memory functions for temporary pool */ ``` -------------------------------- ### Allocate Memory for LZMA (C) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt Defines functions for allocating and freeing memory, used by the LZMA SDK. These functions wrap MyAlloc and MyFree, likely custom memory management functions. ```C static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } static void SzFree(void *p, void *address) { p = p; MyFree(address); } static ISzAlloc g_Alloc = { SzAlloc, SzFree }; ``` -------------------------------- ### Set LZMA Encoder Properties (C) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt Sets the LZMA encoder properties for the given encoder handle. This configures the encoder with the specified compression settings. ```C res = LzmaEnc_SetProps(enc, &props); ``` -------------------------------- ### Handling Attributes Property in 7z FilesInfo Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/7zFormat.txt This code snippet handles the kAttributes property within the 7z FilesInfo section. It checks if all attributes are defined and reads attribute values for defined attributes. ```c++ kAttributes: (0x15) BYTE AllAreDefined if (AllAreDefined == 0) { for(NumFiles) BIT AttributesAreDefined } BYTE External; if(External != 0) UINT64 DataIndex [] for(Definded Attributes) UINT32 Attributes [] ``` -------------------------------- ### Defining Memory Allocation Debug Flag Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/7zC.txt This defines a debug flag, `_SZ_ALLOC_DEBUG`, that, when enabled, prints allocation and deallocation operations to stderr. This is useful for debugging memory-related issues in the 7z decoder. ```C #define _SZ_ALLOC_DEBUG ``` -------------------------------- ### Compiler Options in Makefile Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/readme.txt These makefile variables control compilation options for 7-Zip, such as using JWasm assembler or disabling RAR support. These options can be configured in cmpl_gcc.mak, var_gcc.mak, and warn_gcc.mak. Modifying these variables allows customization of the build process. ```Makefile USE_JWASM=1 ``` ```Makefile DISABLE_RAR=1 ``` ```Makefile DISABLE_RAR_COMPRESS=1 ``` -------------------------------- ### IOutStream SetSize Method Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C++ code snippet shows the change in the SetSize method of the IOutStream interface. The parameter type was changed from Int64 to UInt64, likely to support larger file sizes. ```C++ IStream.h::IOutStream:: STDMETHOD(SetSize)(Int64 newSize) PURE; was changed to STDMETHOD(SetSize)(UInt64 newSize) PURE; ``` -------------------------------- ### LZMA Decoder Optimization Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This assembly code snippet represents an optimized LZMA decoder for x64 architecture. It is written in assembly language and provides a significant speed improvement compared to the C version of the LZMA decoder. ```Assembly Asm\x86\LzmaDecOpt.asm ``` -------------------------------- ### IArchiveGetRawProps Interface Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This code snippet indicates that the IArchiveGetRawProps interface was disabled for 7z archives in versions 9.31-9.37. This interface likely provided access to raw properties of the archive. ```C++ CPP\7zip\Archive\7z\ ``` -------------------------------- ### Multi-call LZMA Decompression Header Reading in C Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt This code snippet shows how to read the LZMA properties and uncompressed size from the header of a compressed file. It reads the first 13 bytes (5 bytes for LZMA properties and 8 bytes for uncompressed size) into a buffer named `header`. This header is then used to allocate the necessary structures for decompression. ```C unsigned char header[LZMA_PROPS_SIZE + 8]; ReadFile(inFile, header, sizeof(header) ``` -------------------------------- ### 7z Header Reading Fix Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C code snippet fixes a bug in the C version of the 7z decoder that caused it to work incorrectly for 7z archives containing empty solid blocks. The fix ensures proper handling of archives with empty solid blocks. ```C 7zArcIn.c ``` -------------------------------- ### LZMA Encoder Bug Fix Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt Fixes a bug in the LZMA encoder in LzmaEnc.c where LzmaEnc_MemEncode(), LzmaEncode() and LzmaCompress() could work incorrectly if the output buffer size is smaller than the required compressed data size. Also addresses issues in LzmaEnc_Encode() and NCompress::NLzma::CEncoder::Code() related to callback function behavior. ```C LzmaEnc_MemEncode(), LzmaEncode() and LzmaCompress() could work incorrectly, if size value for output buffer is smaller than size required for all compressed data. LzmaEnc_Encode() could work incorrectly, if callback ISeqOutStream::Write() doesn't write all compressed data. NCompress::NLzma::CEncoder::Code() could work incorrectly, if callback ISequentialOutStream::Write() returns error code. ``` -------------------------------- ### Reading Property Type in 7z FilesInfo Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/7zFormat.txt This code snippet reads the property type from the 7z FilesInfo section. It checks if the property type is 0 to break the loop, indicating the end of properties. ```c++ BYTE PropertyType; if (aType == 0) break; ``` -------------------------------- ### Return Result of LZMA Operation (C) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt Returns the result of an LZMA operation. This snippet likely represents the return statement within a function that performs LZMA compression or decompression. ```C return res; ``` -------------------------------- ### 7z Archive Extraction Function Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/7zC.txt The `SzAr_Extract` function extracts a file from a 7z archive. It requires the archive database, input stream, file index, and memory allocators. It outputs the extracted file into a buffer allocated with the main allocator. ```C SZ_RESULT SzAr_Extract( CArchiveDatabaseEx *db, ILookInStream *inStream, 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); ``` -------------------------------- ### New Handler Implementation Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C++ code snippet redefines the operator new() only for older MSVC compilers. This ensures compatibility and proper memory allocation behavior across different compiler versions. ```C++ NewHandler.h ``` ```C++ NewHandler.cpp ``` -------------------------------- ### LZMA Encoding Bug Fix Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C code snippet fixes a bug in the LZMA/LZMA2 encoding code that caused incorrect behavior when the input data size was larger than (4 GiB - dictionary_size). The fix ensures correct encoding for large input data sizes. ```C LzFind.c::MatchFinder_ReadBlock() ``` -------------------------------- ### LZMA2 Decoding Error Fix Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C code snippet fixes a bug in the C version of the 7z decoder that could mistakenly report a decoding error for some 7z archives using LZMA2 compression. The fix ensures accurate decoding of LZMA2 compressed archives. ```C 7zDec.c ``` -------------------------------- ### Free LZMA Decoder Structures (C) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt Frees the memory allocated for the LZMA decoder state. This should be called after the LZMA stream has been completely decoded to prevent memory leaks. g_Alloc is assumed to be a custom memory allocator. ```C LzmaDec_Free(&state, &g_Alloc); ``` -------------------------------- ### Write LZMA Properties to Header (C) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt Writes the encoded LZMA properties and file size to the header of the compressed data. This header is required for decompression. MyWriteFileAndCheck is assumed to be a custom write function with error checking. ```C Byte header[LZMA_PROPS_SIZE + 8]; size_t headerSize = LZMA_PROPS_SIZE; UInt64 fileSize; int i; res = LzmaEnc_WriteProperties(enc, header, &headerSize); fileSize = MyGetFileLength(inFile); for (i = 0; i < 8; i++) header[headerSize++] = (Byte)(fileSize >> (8 * i)); MyWriteFileAndCheck(outFile, header, headerSize) ``` -------------------------------- ### LZMA Memory Encoding Function Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C code snippet shows the LzmaEnc_MemEncode() and LzmaEncode() functions, which are used for compressing data from memory to memory using the LZMA algorithm. These functions are part of the LZMA encoding library. ```C LZMA : LzmaEnc_MemEncode(), LzmaEncode() ``` -------------------------------- ### 7z Header Reading Function Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C code snippet shows the SzReadHeader2() function, which is part of the 7z decoder. This function is responsible for reading the header information from 7z archives. ```C 7zArcIn.c : SzReadHeader2() ``` -------------------------------- ### 7zTypes Interface Structure Modification Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C header file snippet shows a change in the names of variables within interface structures. The variables are renamed to 'vt', likely for consistency or clarity within the codebase. ```C C/7zTypes.h ``` -------------------------------- ### OutBuffer Stream Usage Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C++ code snippet shows the usage of ISequentialOutStream in the COutBuffer class. It uses a raw pointer instead of a smart pointer for the stream, which might have implications for memory management. ```C++ OutBuffer.h: COutBuffer uses ISequentialOutStream *_stream; ``` -------------------------------- ### Split Archive Size Fix Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C++ code snippet fixes a bug in the Split Handler that caused it to return an incorrect total size value for split archives. This ensures accurate size reporting for split archive files. ```C++ SplitHandler.cpp ``` -------------------------------- ### InBuffer Stream Usage Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C++ code snippet shows the usage of ISequentialInStream in the CInBuffer class. It uses a raw pointer instead of a smart pointer for the stream, which might have implications for memory management. ```C++ InBuffer.h : CInBuffer uses ISequentialInStream *_stream; ``` -------------------------------- ### LZMA2 Decoding Function Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C code snippet shows the SzDecodeLzma2() function, which is part of the 7z decoder. This function is responsible for decoding LZMA2 compressed data within 7z archives. ```C 7zDec.c : SzDecodeLzma2() ``` -------------------------------- ### LZMA2 Chunk Size Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/src-history.txt This C++ code snippet relates to the multi-threaded version of the LZMA2 encoder. It highlights a bug fix related to the chunk size (CLzma2EncProps::blockSize) when its value is larger than (4 GiB - dictionary_size). ```C++ CLzma2EncProps::blockSize ``` -------------------------------- ### Destroy LZMA Encoder Object (C) Source: https://github.com/nvidia-omniverse/ext-7z/blob/main/DOC/lzma.txt Destroys the LZMA encoder object and frees any associated memory. This should be called after encoding is complete to prevent memory leaks. ```C LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.