### Swift Package Manager Installation Source: https://github.com/tsolomko/swcompression/blob/develop/README.md Demonstrates how to add SWCompression as a dependency to your Swift project using Swift Package Manager. This is the recommended method for integrating the library. ```swift import PackageDescription let package = Package( name: "PackageName", dependencies: [ .package(name: "SWCompression", url: "https://github.com/tsolomko/SWCompression.git", from: "4.8.0") ], targets: [ .target( name: "TargetName", dependencies: ["SWCompression"]) ] ) ``` -------------------------------- ### Handle Compressed TAR Archives in Swift Source: https://context7.com/tsolomko/swcompression/llms.txt Provides examples for extracting and creating compressed TAR archives (.tar.gz, .tar.bz2, .tar.xz) using SWCompression. It demonstrates chaining decompression with TAR container opening and creating a new .tar.gz archive from Swift Data. ```swift import SWCompression // Extract a .tar.gz file let tarGzData: Data = ... // Your .tar.gz file let tarData = try GzipArchive.unarchive(archive: tarGzData) let entries = try TarContainer.open(container: tarData) for entry in entries { print("Extracted: \(entry.info.name)") } // Extract a .tar.bz2 file let tarBz2Data: Data = ... // Your .tar.bz2 file let tarFromBz2 = try BZip2.decompress(data: tarBz2Data) let bz2Entries = try TarContainer.open(container: tarFromBz2) // Extract a .tar.xz file let tarXzData: Data = ... // Your .tar.xz file let tarFromXz = try XZArchive.unarchive(archive: tarXzData) let xzEntries = try TarContainer.open(container: tarFromXz) // Create a .tar.gz file var info = TarEntryInfo(name: "readme.txt", type: .regular) let entry = TarEntry(info: info, data: "Hello, World!".data(using: .utf8)!) let newTarData = TarContainer.create(from: [entry]) let compressedTarGz = try GzipArchive.archive( data: newTarData, fileName: "archive.tar" ) print("Created .tar.gz of \(compressedTarGz.count) bytes") ``` -------------------------------- ### Basic Data Decompression (Deflate) Source: https://github.com/tsolomko/swcompression/blob/develop/README.md Shows a simple example of how to decompress data that has been compressed using the Deflate algorithm. This function takes compressed data as input and returns the decompressed data. ```swift // let data = let decompressedData = try? Deflate.decompress(data: data) ``` -------------------------------- ### XZ Archive Unarchiving with Error Handling Source: https://github.com/tsolomko/swcompression/blob/develop/README.md Provides an example of unarchiving data from an XZ archive, including a robust error handling mechanism. It demonstrates how to catch specific XZ errors and general errors. ```swift do { // let data = let decompressedData = try XZArchive.unarchive(archive: data) } catch let error as XZError { // } catch let error { // } ``` -------------------------------- ### Stream TAR Archives with TarReader Source: https://context7.com/tsolomko/swcompression/llms.txt Shows how to read large TAR archives iteratively from a FileHandle to optimize memory usage. It provides examples for both automatic processing and manual entry reading. ```swift import SWCompression import Foundation let fileURL = URL(fileURLWithPath: "/path/to/archive.tar") let fileHandle = try FileHandle(forReadingFrom: fileURL) defer { try? fileHandle.close() } var reader = TarReader(fileHandle: fileHandle) while let entry = try reader.read() { print("Entry: \(entry.info.name)") } ``` -------------------------------- ### Unarchive XZ Data with SWCompression Source: https://context7.com/tsolomko/swcompression/llms.txt Demonstrates how to decompress XZ data using XZArchive. It includes error handling for common XZ issues and shows how to process multi-stream archives while preserving boundaries. ```swift import SWCompression // Unarchive XZ data (single output) let xzData: Data = ... // Your .xz file data do { let decompressedData = try XZArchive.unarchive(archive: xzData) print("Unarchived \(decompressedData.count) bytes") } catch let error as XZError { switch error { case .wrongCheck(let partialData): print("Check failed, recovered \(partialData.count) items") case .wrongMagic: print("Not a valid XZ file") case .wrongFilterID: print("Unsupported filter (only LZMA2 is supported)") default: print("XZ error: \(error)") } } // Unarchive multi-stream XZ (preserves stream boundaries) let multiStreamXz: Data = ... // XZ with multiple streams let streams = try XZArchive.splitUnarchive(archive: multiStreamXz) for (index, streamData) in streams.enumerated() { print("Stream \(index): \(streamData.count) bytes") } ``` -------------------------------- ### LZ4 Compression and Decompression in Swift Source: https://context7.com/tsolomko/swcompression/llms.txt Demonstrates how to compress and decompress data using the LZ4 algorithm with the SWCompression library. Supports simple operations, multi-frame data, custom compression options, and external dictionaries. Error handling for checksum mismatches and data corruption is included. ```swift import SWCompression // Simple decompression let lz4Data: Data = ... // Your LZ4-compressed data do { let decompressedData = try LZ4.decompress(data: lz4Data) print("Decompressed \(decompressedData.count) bytes") } catch let error as DataError { switch error { case .checksumMismatch(let partialData): print("Checksum mismatch, recovered data: \(partialData)") case .truncated: print("Data is truncated") case .corrupted: print("Data is corrupted") default: print("Error: \(error)") } } // Decompress multi-frame LZ4 data let multiFrameData: Data = ... // Multiple concatenated LZ4 frames let frames = try LZ4.multiDecompress(data: multiFrameData) for (index, frame) in frames.enumerated() { print("Frame \(index): \(frame.count) bytes") } // Simple compression with default options let originalData = "Compress this text with LZ4!".data(using: .utf8)! let compressed = LZ4.compress(data: originalData) print("Compressed to \(compressed.count) bytes") // Compression with custom options let largeData = Data(count: 1_000_000) let customCompressed = LZ4.compress( data: largeData, independentBlocks: false, // Use dependent blocks for better ratio blockChecksums: true, // Add checksums to each block contentChecksum: true, // Add checksum for entire content contentSize: true, // Store uncompressed size blockSize: 256 * 1024 // Use 256KB blocks ) print("Compressed with custom options: \(customCompressed.count) bytes") // Compression with external dictionary let dictionary = "common phrases and patterns".data(using: .utf8)! let similarData = "common phrases with variations".data(using: .utf8)! let dictCompressed = LZ4.compress( data: similarData, independentBlocks: true, blockChecksums: false, contentChecksum: true, contentSize: false, dictionary: dictionary, dictionaryID: 12345 ) ``` -------------------------------- ### Manage TAR Archives with TarContainer Source: https://context7.com/tsolomko/swcompression/llms.txt Demonstrates how to open, inspect, and create TAR archives using the TarContainer class. It covers reading entry metadata, detecting archive formats, and creating new archives with custom entry information. ```swift import SWCompression let tarData: Data = ... do { let entries = try TarContainer.open(container: tarData) for entry in entries { print("Entry: \(entry.info.name)") } } catch let error as TarError { print("TAR error: \(error)") } let format = try TarContainer.formatOf(container: tarData) var info = TarEntryInfo(name: "myfile.txt", type: .regular) let entry = TarEntry(info: info, data: "File contents here".data(using: .utf8)!) let newTarData = TarContainer.create(from: [entry]) ``` -------------------------------- ### Zlib Archive Handling in Swift Source: https://context7.com/tsolomko/swcompression/llms.txt Demonstrates the usage of the ZlibArchive class for compressing and decompressing data using the Zlib algorithm. This is useful for network protocols and file formats like PNG. Includes error handling for Adler32 mismatches and invalid Zlib archives. ```swift import SWCompression // Unarchive Zlib data let zlibData: Data = ... // Your Zlib-compressed data do { let decompressedData = try ZlibArchive.unarchive(archive: zlibData) print("Unarchived \(decompressedData.count) bytes") } catch let error as ZlibError { switch error { case .wrongAdler32(let data): print("Adler32 mismatch, recovered \(data.count) bytes") case .wrongMagic: print("Not a valid Zlib archive") default: print("Zlib error: \(error)") } } // Create a Zlib archive let originalData = "Data to compress with Zlib".data(using: .utf8)! let zlibArchive = ZlibArchive.archive(data: originalData) print("Created Zlib archive of \(zlibArchive.count) bytes") // Round-trip test let restored = try ZlibArchive.unarchive(archive: zlibArchive) assert(restored == originalData) ``` -------------------------------- ### Stream TAR Archives with TarWriter Source: https://context7.com/tsolomko/swcompression/llms.txt Illustrates how to create large TAR archives incrementally by writing entries one at a time to a FileHandle. This approach is essential for memory-efficient archive generation. ```swift import SWCompression import Foundation let outputURL = URL(fileURLWithPath: "/path/to/output.tar") FileManager.default.createFile(atPath: outputURL.path, contents: nil) let fileHandle = try FileHandle(forWritingTo: outputURL) defer { try? fileHandle.close() } var writer = TarWriter(fileHandle: fileHandle, force: .pax) let entry = TarEntry(info: TarEntryInfo(name: "file.txt", type: .regular), data: Data()) try writer.append(entry) try writer.finalize() ``` -------------------------------- ### swcomp tar Command Enhancements Source: https://github.com/tsolomko/swcompression/blob/develop/CHANGELOG.md New command-line options and output improvements for the `tar` command in swcomp. ```APIDOC ## swcomp tar Command Enhancements ### Description This section details the new features and improvements for the `tar` command-line tool within swcomp. ### Method Command-line tool ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```bash # Create a new TAR container swcomp tar -c -f output.tar input_files... # Get the format of a TAR container swcomp tar -f my_archive.tar --format ``` ### Response N/A (Command-line output) ### New Features: - Added `-c`, `--create` option to create a new TAR container. - Output of benchmark commands is now properly flushed on non-Linux platforms. - Results for omitted iterations of benchmark commands are now printed. - Iteration number in benchmark commands is now printed with leading zeros. - Fixed compilation error on Linux due to `ObjCBool`. ``` -------------------------------- ### Read and Inspect ZIP Containers Source: https://context7.com/tsolomko/swcompression/llms.txt Shows how to open ZIP archives, iterate through entries, and access metadata. It also demonstrates how to retrieve entry information without full decompression and how to register custom extra field handlers. ```swift import SWCompression // Open ZIP container and access entries let zipData: Data = ... // Your .zip file data do { let entries = try ZipContainer.open(container: zipData) for entry in entries { print("Entry: \(entry.info.name)") print(" Type: \(entry.info.type)") print(" Compressed size: \(entry.info.compressedSize ?? 0)") print(" Uncompressed size: \(entry.info.size ?? 0)") print(" Compression: \(entry.info.compressionMethod)") print(" CRC32: \(entry.info.crc ?? 0)") if let data = entry.data { print(" Data: \(data.count) bytes") } if let modTime = entry.info.modificationTime { print(" Modified: \(modTime)") } if let permissions = entry.info.permissions { print(" Permissions: \(permissions)") } } } catch let error as ZipError { switch error { case .wrongCRC(let partialEntries): print("CRC error, extracted \(partialEntries.count) entries before error") case .compressionNotSupported: print("Unsupported compression method") case .notFoundCentralDirectoryEnd: print("Not a valid ZIP file") default: print("ZIP error: \(error)") } } // Get only entry information (faster, no decompression) let entryInfos = try ZipContainer.info(container: zipData) for info in entryInfos { print("\(info.name): \(info.size ?? 0) bytes") } // Register custom extra field handler struct MyCustomExtraField: ZipExtraField { static let id: UInt16 = 0x1234 let customData: Data init?(data: Data, location: ZipExtraFieldLocation) { self.customData = data } } ZipContainer.customExtraFields[MyCustomExtraField.id] = MyCustomExtraField.self ``` -------------------------------- ### Open and Read 7-Zip Archives in Swift Source: https://context7.com/tsolomko/swcompression/llms.txt Demonstrates how to open a 7-Zip container from Data, iterate through its entries, access entry information (name, type, size, CRC32, modification time, DOS attributes), and extract entry data. It also shows how to retrieve only entry information without decompressing the data. Handles potential SevenZipErrors. ```swift import SWCompression // Open 7-Zip container and access entries let sevenZipData: Data = ... // Your .7z file data do { let entries = try SevenZipContainer.open(container: sevenZipData) for entry in entries { print("Entry: \(entry.info.name)") print(" Type: \(entry.info.type)") print(" Size: \(entry.info.size ?? 0)") if let crc = entry.info.crc { print(" CRC32: \(crc)") } if let modTime = entry.info.modificationTime { print(" Modified: \(modTime)") } if let dosAttrs = entry.info.dosAttributes { print(" DOS Attributes: \(dosAttrs)") } if let data = entry.data { print(" Data: \(data.count) bytes") } } } catch let error as SevenZipError { switch error { case .wrongSignature: print("Not a valid 7-Zip file") case .wrongCRC: print("CRC verification failed") case .internalStructureError: print("Corrupted archive structure") default: print("7-Zip error: \(error)") } } // Get only entry information (no decompression) let entryInfos = try SevenZipContainer.info(container: sevenZipData) for info in entryInfos { let sizeStr = info.size.map { "\($0) bytes" } ?? "unknown size" print("\(info.name): \(sizeStr)") } ``` -------------------------------- ### Deflate Compression and Decompression in Swift Source: https://context7.com/tsolomko/swcompression/llms.txt Provides static methods for compressing and decompressing data using the Deflate algorithm. Handles errors during decompression and optimizes compression based on data characteristics. No external dependencies are required. ```swift import SWCompression // Decompress Deflate-compressed data let compressedData: Data = ... // Your deflate-compressed data do { let decompressedData = try Deflate.decompress(data: compressedData) print("Decompressed \(decompressedData.count) bytes") } catch let error as DeflateError { print("Deflate error: \(error)") } // Compress data using Deflate let originalData = "Hello, World! This is some text to compress.".data(using: .utf8)! let deflatedData = Deflate.compress(data: originalData) print("Compressed from \(originalData.count) to \(deflatedData.count) bytes") // Round-trip compression test let restored = try Deflate.decompress(data: deflatedData) assert(restored == originalData) ``` -------------------------------- ### GZip Archive Handling in Swift Source: https://context7.com/tsolomko/swcompression/llms.txt Provides functionality for creating and extracting GZip archives using the SWCompression library. Supports single and multi-member archives, custom metadata in headers (filename, comment, modification time), and CRC32 validation. Includes error handling for CRC errors and invalid GZip formats. ```swift import SWCompression // Unarchive a GZip file let gzipData: Data = ... // Your .gz file data do { let decompressedData = try GzipArchive.unarchive(archive: gzipData) print("Unarchived \(decompressedData.count) bytes") } catch let error as GzipError { switch error { case .wrongCRC(let members): print("CRC error in member, got \(members.count) members before error") case .wrongMagic: print("Not a valid GZip file") default: print("GZip error: \(error)") } } // Unarchive multi-member GZip archive let multiMemberGzip: Data = ... // GZip with multiple members let members = try GzipArchive.multiUnarchive(archive: multiMemberGzip) for member in members { print("Member: \(member.header.fileName ?? \"unnamed\")") print(" Data size: \(member.data.count) bytes") print(" Modification time: \(member.header.modificationTime ?? Date())") } // Create a GZip archive with metadata let dataToArchive = "Important content to compress".data(using: .utf8)! let gzipArchive = try GzipArchive.archive( data: dataToArchive, comment: "Created by SWCompression", fileName: "document.txt", writeHeaderCRC: true, isTextFile: true, osType: .unix, modificationTime: Date() ) print("Created archive of \(gzipArchive.count) bytes") // Simple archive without metadata let simpleArchive = try GzipArchive.archive(data: dataToArchive) ``` -------------------------------- ### XZ Archive Handling Source: https://context7.com/tsolomko/swcompression/llms.txt Provides functions for unarchiving XZ-compressed data, including single output and multi-stream support with error handling for various XZ-specific issues. ```APIDOC ## XZ Archive Handling ### Description The XZArchive class provides unarchiving functions for XZ-compressed data. XZ uses LZMA2 compression and supports multi-stream archives with various integrity check types (CRC32, CRC64, SHA-256). ### Unarchive XZ data (single output) ```swift import SWCompression let xzData: Data = ... // Your .xz file data do { let decompressedData = try XZArchive.unarchive(archive: xzData) print("Unarchived \(decompressedData.count) bytes") } catch let error as XZError { switch error { case .wrongCheck(let partialData): print("Check failed, recovered \(partialData.count) items") case .wrongMagic: print("Not a valid XZ file") case .wrongFilterID: print("Unsupported filter (only LZMA2 is supported)") default: print("XZ error: \(error)") } } ``` ### Unarchive multi-stream XZ (preserves stream boundaries) ```swift import SWCompression let multiStreamXz: Data = ... // XZ with multiple streams let streams = try XZArchive.splitUnarchive(archive: multiStreamXz) for (index, streamData) in streams.enumerated() { print("Stream \(index): \(streamData.count) bytes") } ``` ``` -------------------------------- ### Deflate Compression and Decompression Source: https://context7.com/tsolomko/swcompression/llms.txt Provides static methods for compressing and decompressing data using the Deflate algorithm. Handles automatic selection of compression strategies and includes error handling for decompression. ```APIDOC ## Deflate Compression and Decompression ### Description Provides static methods for compressing and decompressing data using the Deflate algorithm. Decompression throws `DeflateError` for corrupted data, while compression optimizes based on data characteristics. ### Method `Deflate.compress(data:)` `Deflate.decompress(data:) throws` ### Endpoint N/A (Static methods) ### Parameters #### Request Body (for compress) - **data** (Data) - Required - The data to be compressed. #### Request Body (for decompress) - **data** (Data) - Required - The Deflate-compressed data. ### Request Example ```swift import SWCompression // Decompress Deflate-compressed data let compressedData: Data = ... // Your deflate-compressed data do { let decompressedData = try Deflate.decompress(data: compressedData) print("Decompressed \(decompressedData.count) bytes") } catch let error as DeflateError { print("Deflate error: \(error)") } // Compress data using Deflate let originalData = "Hello, World! This is some text to compress.".data(using: .utf8)! let deflatedData = Deflate.compress(data: originalData) print("Compressed from \(originalData.count) to \(deflatedData.count) bytes") ``` ### Response #### Success Response (compress) - **Data** (Data) - The Deflate-compressed data. #### Success Response (decompress) - **Data** (Data) - The decompressed data. #### Error Response (decompress) - **DeflateError** - Thrown if the data is damaged or not Deflate-compressed. #### Response Example (decompress success) ```json { "example": "decompressed data" } ``` #### Response Example (compress success) ```json { "example": "deflated data" } ``` ``` -------------------------------- ### BZip2 Compression and Decompression in Swift Source: https://context7.com/tsolomko/swcompression/llms.txt Offers compression and decompression using the BZip2 algorithm with configurable block sizes for compression ratio and memory usage. Decompression includes CRC32 checksum validation for data integrity. The framework is written in Swift. ```swift import SWCompression // Decompress BZip2-compressed data let bz2Data: Data = ... // Your BZip2-compressed data do { let decompressedData = try BZip2.decompress(data: bz2Data) print("Decompressed \(decompressedData.count) bytes") } catch let error as BZip2Error { switch error { case .wrongCRC(let partialData): print("CRC mismatch, recovered \(partialData.count) bytes") case .wrongMagic: print("Not a valid BZip2 file") default: print("BZip2 error: \(error)") } } // Compress data using BZip2 with default block size (100KB) let originalData = Data(repeating: 0x42, count: 10000) let compressedData = BZip2.compress(data: originalData) print("Compressed to \(compressedData.count) bytes") // Compress with custom block size (900KB for better compression ratio) let largeData = Data(count: 500_000) let compressedLarge = BZip2.compress(data: largeData, blockSize: .nine) print("Compressed large data to \(compressedLarge.count) bytes") ``` -------------------------------- ### TarContainer Creation API Source: https://github.com/tsolomko/swcompression/blob/develop/CHANGELOG.md APIs for creating new TAR containers, including error handling for UTF-8 encoding issues. ```APIDOC ## TarContainer Creation API ### Description This section details the APIs for creating new TAR containers and the associated error types. ### Method N/A (API functions) ### Endpoint N/A (In-memory operations) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```swift // Example usage of TarContainer.create(from:) let newTarContainer = TarContainer.create(from: someData) ``` ### Response #### Success Response (N/A) - **TarContainer** (TarContainer) - A newly created TAR container. #### Response Example N/A ### Error Handling - **TarCreateError**: An error type with a single case `utf8NonEncodable` indicating that the provided data could not be encoded as UTF-8. ```swift try { let newTarContainer = try TarContainer.create(from: someData) } catch TarCreateError.utf8NonEncodable { print("Error: Data is not UTF-8 encodable.") } ``` ``` -------------------------------- ### GZip Archive Unarchiving Source: https://github.com/tsolomko/swcompression/blob/develop/README.md Illustrates how to unarchive data compressed in the GZip format. This is a common use case when dealing with compressed files or streams. ```swift let decompressedData = try? GzipArchive.unarchive(archive: data) ``` -------------------------------- ### BZip2 Compression and Decompression Source: https://context7.com/tsolomko/swcompression/llms.txt Offers compression and decompression using the BZip2 algorithm. Supports configurable block sizes for compression and validates CRC32 checksums during decompression. ```APIDOC ## BZip2 Compression and Decompression ### Description Provides compression and decompression using the BZip2 algorithm. Compression allows for configurable block sizes (100KB to 900KB), affecting compression ratio and memory usage. Decompression includes CRC32 checksum validation for data integrity. ### Method `BZip2.compress(data: blockSize:)` `BZip2.decompress(data:) throws` ### Endpoint N/A (Static methods) ### Parameters #### Request Body (for compress) - **data** (Data) - Required - The data to be compressed. - **blockSize** (BZip2.BlockSize) - Optional - The block size for compression, defaults to `.oneHundredKB`. #### Request Body (for decompress) - **data** (Data) - Required - The BZip2-compressed data. ### Request Example ```swift import SWCompression // Decompress BZip2-compressed data let bz2Data: Data = ... // Your BZip2-compressed data do { let decompressedData = try BZip2.decompress(data: bz2Data) print("Decompressed \(decompressedData.count) bytes") } catch let error as BZip2Error { switch error { case .wrongCRC(let partialData): print("CRC mismatch, recovered \(partialData.count) bytes") case .wrongMagic: print("Not a valid BZip2 file") default: print("BZip2 error: \(error)") } } // Compress data using BZip2 with default block size (100KB) let originalData = Data(repeating: 0x42, count: 10000) let compressedData = BZip2.compress(data: originalData) print("Compressed to \(compressedData.count) bytes") // Compress with custom block size (900KB for better compression ratio) let largeData = Data(count: 500_000) let compressedLarge = BZip2.compress(data: largeData, blockSize: .nine) print("Compressed large data to \(compressedLarge.count) bytes") ``` ### Response #### Success Response (compress) - **Data** (Data) - The BZip2-compressed data. #### Success Response (decompress) - **Data** (Data) - The decompressed data. #### Error Response (decompress) - **BZip2Error** - Thrown for various issues like CRC mismatch (`.wrongCRC`), invalid format (`.wrongMagic`), etc. #### Response Example (decompress success) ```json { "example": "decompressed bz2 data" } ``` #### Response Example (compress success) ```json { "example": "compressed bz2 data" } ``` ``` -------------------------------- ### Archive Handling API Source: https://github.com/tsolomko/swcompression/blob/develop/README.md Methods for unarchiving container formats like GZip, ZIP, or TAR. ```APIDOC ## Archive Unarchiving ### Description Extracts content from supported archive formats. ### Method Static Method ### Parameters #### Request Body - **archive** (Data) - Required - The archive file data. ### Request Example ```swift let data = ``` ### Response #### Success Response (200) - **decompressedData** (Data) - The extracted data from the archive. ### Response Example ```swift let decompressedData = try? GzipArchive.unarchive(archive: data) ``` ``` -------------------------------- ### TarEntry and TarEntryInfo Modifications Source: https://github.com/tsolomko/swcompression/blob/develop/CHANGELOG.md Details on changes to TarEntry and TarEntryInfo properties, including initializers and mutability. ```APIDOC ## TarEntry and TarEntryInfo Modifications ### Description This section describes the updates to `TarEntry.info`, `TarEntry.data`, and various initializers for `TarEntry` and `TarEntryInfo`. ### Method N/A (API functions) ### Endpoint N/A (In-memory operations) ### Parameters N/A ### Request Example N/A ### Response N/A ### Key Changes: - `TarEntry.info` and `TarEntry.data` are now mutable (`var`). - Setting `TarEntry.data` automatically updates `TarEntry.info.size`. - New initializer `TarEntry.init(info:data:)` is available. - Most public properties of `TarEntry` are now `var`, except `size` and `type`. - New initializer `TarEntryInfo.init(name:type:)` is available. ``` -------------------------------- ### LZMA Decompression in Swift Source: https://context7.com/tsolomko/swcompression/llms.txt Enables decompression of LZMA-compressed data, supporting both standard LZMA format with embedded properties and raw LZMA streams with custom properties. This algorithm is known for its high compression ratios and is commonly used in 7-Zip archives. The implementation is pure Swift. ```swift import SWCompression // Decompress standard LZMA data (with embedded properties and size) let lzmaData: Data = ... // Your LZMA-compressed data do { let decompressedData = try LZMA.decompress(data: lzmaData) print("Decompressed \(decompressedData.count) bytes") } catch let error as LZMAError { print("LZMA error: \(error)") } // Decompress LZMA data with custom properties (advanced usage) let rawLzmaStream: Data = ... // Raw LZMA stream without header let properties = LZMAProperties(lc: 3, lp: 0, pb: 2, dictionarySize: 1 << 24) do { // When uncompressedSize is nil, data must contain finish marker let decompressedData = try LZMA.decompress( data: rawLzmaStream, properties: properties, uncompressedSize: 65536 // Optional: specify expected output size ) print("Decompressed \(decompressedData.count) bytes") } catch let error as LZMAError { print("LZMA error: \(error)") } ``` -------------------------------- ### TAR Format Compatibility Improvements Source: https://github.com/tsolomko/swcompression/blob/develop/CHANGELOG.md Enhancements to TAR format compatibility, including UTF-8 string handling, numeric field parsing, and extended header processing. ```APIDOC ## TAR Format Compatibility Improvements ### Description This section outlines the improvements made to enhance compatibility with various TAR implementations and formats. ### Method N/A (API functions) ### Endpoint N/A (In-memory operations) ### Parameters N/A ### Request Example N/A ### Response N/A ### Improvements: - String fields in TAR headers are now treated as UTF-8. - Non-well-formed integer fields result in `nil` for corresponding `TarEntryInfo` properties (except `size`). - Support for Base-256 encoding in numeric fields. - Correct skipping of leading NULLs and whitespaces in numeric fields. - Sun Extended Headers are processed as local PAX extended headers. - Partial support for GNU TAR incremental backup features (access and creation time). - `TarContainer.formatOf` now correctly identifies `TarFormat.gnu`. - A new `Data` object is created for `TarEntry.data` to avoid slicing. - Fixed incorrect file names for entries in GNU format containers. - Fixed `TarError.wrongPaxHeaderEntry` for headers with multi-byte UTF-8 characters. - Fixed incorrect values for `ownerID`, `groupID`, `deviceMajorNumber`, and `deviceMinorNumber`. ``` -------------------------------- ### ZIP Container Handling Source: https://context7.com/tsolomko/swcompression/llms.txt Enables reading ZIP archives with support for multiple compression methods, ZIP64 extensions, custom extra fields, and provides options to retrieve full entry data or just entry information. ```APIDOC ## ZIP Container Handling ### Description The ZipContainer class provides functions for reading ZIP archives. It supports multiple compression methods (Store, Deflate, BZip2, LZMA), ZIP64 extensions, and custom extra fields. ### Open ZIP container and access entries ```swift import SWCompression let zipData: Data = ... // Your .zip file data do { let entries = try ZipContainer.open(container: zipData) for entry in entries { print("Entry: \(entry.info.name)") print(" Type: \(entry.info.type)") print(" Compressed size: \(entry.info.compressedSize ?? 0)") print(" Uncompressed size: \(entry.info.size ?? 0)") print(" Compression: \(entry.info.compressionMethod)") print(" CRC32: \(entry.info.crc ?? 0)") if let data = entry.data { print(" Data: \(data.count) bytes") } if let modTime = entry.info.modificationTime { print(" Modified: \(modTime)") } if let permissions = entry.info.permissions { print(" Permissions: \(permissions)") } } } catch let error as ZipError { switch error { case .wrongCRC(let partialEntries): print("CRC error, extracted \(partialEntries.count) entries before error") case .compressionNotSupported: print("Unsupported compression method") case .notFoundCentralDirectoryEnd: print("Not a valid ZIP file") default: print("ZIP error: \(error)") } } ``` ### Get only entry information (faster, no decompression) ```swift import SWCompression let entryInfos = try ZipContainer.info(container: zipData) for info in entryInfos { print("\(info.name): \(info.size ?? 0) bytes") } ``` ### Register custom extra field handler ```swift import SWCompression struct MyCustomExtraField: ZipExtraField { static let id: UInt16 = 0x1234 let customData: Data init?(data: Data, location: ZipExtraFieldLocation) { self.customData = data } } ZipContainer.customExtraFields[MyCustomExtraField.id] = MyCustomExtraField.self ``` ``` -------------------------------- ### ZipExtraField Protocol and Usage Source: https://github.com/tsolomko/swcompression/blob/develop/CHANGELOG.md APIs for using custom ZIP Extra Fields, including a new protocol and enum for managing them. ```APIDOC ## ZipExtraField Protocol and Usage ### Description This section describes the new APIs that allow the use of custom ZIP Extra Fields within ZIP containers. ### Method N/A (API functions) ### Endpoint N/A (In-memory operations) ### Parameters N/A ### Request Example ```swift // Example of defining and using a custom ZipExtraField struct MyCustomField: ZipExtraField { let id: ZipExtraField.ID = "ABCD" let data: Data init(data: Data) throws { self.data = data } } // Assuming zipContainer is an instance of ZipContainer zipContainer.customExtraFields.append(MyCustomField(data: someData)) ``` ### Response N/A ### New APIs: - `ZipExtraField` protocol: Defines the interface for custom extra fields. - `ZipExtraFieldLocation` enum: Specifies the location of extra fields. - `ZipContainer.customExtraFields` property: Allows access to custom extra fields in a container. - `ZipEntryInfo.customExtraFields` property: Allows access to custom extra fields for an entry. ``` -------------------------------- ### Decompression API Source: https://github.com/tsolomko/swcompression/blob/develop/README.md Methods for decompressing raw data or archives using supported algorithms. ```APIDOC ## Decompression API ### Description Provides static methods to decompress data streams or extract archives. ### Method Static Method ### Parameters #### Request Body - **data** (Data) - Required - The compressed data or archive to process. ### Request Example ```swift let data = ``` ### Response #### Success Response (200) - **decompressedData** (Data) - The resulting uncompressed data. ### Response Example ```swift let decompressedData = try? Deflate.decompress(data: data) ``` ``` -------------------------------- ### TarContainer Format Identification Source: https://github.com/tsolomko/swcompression/blob/develop/CHANGELOG.md APIs for identifying the format of TAR containers and the corresponding enum for TAR formats. ```APIDOC ## TarContainer Format Identification ### Description This section details the APIs for determining the format of a TAR container and the enum representing different TAR formats. ### Method N/A (API functions) ### Endpoint N/A (In-memory operations) ### Parameters N/A ### Request Example ```swift let containerURL = URL(fileURLWithPath: "my_archive.tar") let format = TarContainer.formatOf(container: containerURL) print("TAR format: \(format)") // Using swcomp command-line tool // swcomp tar -f my_archive.tar --format ``` ### Response #### Success Response (N/A) - **TarContainer.Format** (TarContainer.Format) - An enum representing the identified TAR format. #### Response Example ```swift // Example output // TAR format: TarFormat.gnu ``` ### New APIs: - `TarContainer.Format` enum: Represents formats like `ustar`, `pax`, `gnu`, etc. - `TarContainer.formatOf(container:)` function: Returns the format of a given TAR container. - `-f`, `--format` option to `swcomp`'s `tar` command: Prints the format of a TAR container. ``` -------------------------------- ### LZMA Decompression Source: https://context7.com/tsolomko/swcompression/llms.txt Provides decompression for LZMA-compressed data, supporting both standard LZMA format and raw LZMA streams with custom properties. ```APIDOC ## LZMA Decompression ### Description Provides decompression for LZMA-compressed data. It supports standard LZMA format (which includes embedded properties and size information) and raw LZMA streams where properties must be provided separately. LZMA is known for its high compression ratios, commonly used in formats like 7-Zip. ### Method `LZMA.decompress(data:) throws` `LZMA.decompress(data: properties: uncompressedSize:) throws` ### Endpoint N/A (Static methods) ### Parameters #### Request Body (for standard decompress) - **data** (Data) - Required - The LZMA-compressed data with embedded properties and size. #### Request Body (for custom properties decompress) - **data** (Data) - Required - The raw LZMA stream data. - **properties** (LZMAProperties) - Required - An object containing LZMA properties (lc, lp, pb, dictionarySize). - **uncompressedSize** (Int?) - Optional - The expected size of the uncompressed data. If nil, the data must contain a finish marker. ### Request Example ```swift import SWCompression // Decompress standard LZMA data (with embedded properties and size) let lzmaData: Data = ... // Your LZMA-compressed data do { let decompressedData = try LZMA.decompress(data: lzmaData) print("Decompressed \(decompressedData.count) bytes") } catch let error as LZMAError { print("LZMA error: \(error)") } // Decompress LZMA data with custom properties (advanced usage) let rawLzmaStream: Data = ... // Raw LZMA stream without header let properties = LZMAProperties(lc: 3, lp: 0, pb: 2, dictionarySize: 1 << 24) do { // When uncompressedSize is nil, data must contain finish marker let decompressedData = try LZMA.decompress( data: rawLzmaStream, properties: properties, uncompressedSize: 65536 // Optional: specify expected output size ) print("Decompressed \(decompressedData.count) bytes") } catch let error as LZMAError { print("LZMA error: \(error)") } ``` ### Response #### Success Response - **Data** (Data) - The decompressed LZMA data. #### Error Response - **LZMAError** - Thrown if decompression fails due to invalid data, incorrect properties, or other LZMA-specific issues. #### Response Example (success) ```json { "example": "decompressed lzma data" } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.