SWCompression

repository·develop·Indexed 43 days ago

https://github.com/tsolomko/swcompression

A Swift-only framework providing a unified API for compression, decompression, and archive formats including ZIP, TAR, 7-Zip, Deflate, BZip2, and LZ4. Designed for Apple platforms, Linux, and Windows, it includes the swcomp CLI tool for file processing and performance benchmarking.

Tokens
1.3K
Snippets
5
Records
10
Agent score
55%

What's inside SWCompression

  1. Relationship between SWCompression and BitByteData performance

    develop
    The overall performance of SWCompression is heavily dependent on the speed of reading and writing bits and bytes, which is handled by the BitByteData framework. When evaluating performance or benchmarking, the version of BitByteData used is a critical factor, as newer versions may contain performance improvements that affect SWCompression's throughput.
  2. Understand the datasets used in SWCompression benchmarks

    develop

    SWCompression benchmarks use three distinct datasets designed to represent real-life scenarios. Note that these test files are not included in the repository itself:

    • Test 1: Git 2.15.0 Source Code.
    • Test 2: Visual Studio Code 1.18.1 App for macOS.
    • Test 3: Documentation directory from Linux kernel 4.14.2 Source Code.
  3. Handle decompression errors

    develop

    Most functions in SWCompression throw errors. While many error cases exist for diagnostic purposes (e.g., XZError.wrongMagic), you should typically catch the specific error type associated with the algorithm you are using to handle format-specific issues.

    do {
        // let data = <Your compressed data>
        let decompressedData = try XZArchive.unarchive(archive: data)
    } catch let error as XZError {
        // <handle XZ related error here>
    } catch let error {
        // <handle all other errors here>
    }
  4. Run benchmarks using the swcomp CLI

    develop

    You can run performance benchmarks for SWCompression using the benchmark command provided by the swcomp CLI tool. To ensure accurate results, benchmarks should be run using the Release configuration. The benchmarks are typically calculated as averages over 10 iterations.

    swcomp benchmark
  5. Install SWCompression via Swift Package Manager

    develop

    To integrate SWCompression into your project, add it as a dependency in your Package.swift file. Specify the repository URL and the minimum version requirement (e.g., 4.9.0).

    import PackageDescription
    
    let package = Package(
        name: "PackageName",
        dependencies: [
            .package(name: "SWCompression", url: "https://github.com/tsolomko/SWCompression.git",
                     from: "4.9.0")
        ],
        targets: [
            .target(
                name: "TargetName",
                dependencies: ["SWCompression"]
            )
        ]
    )
  6. Decompress data using Deflate or GZip

    develop

    SWCompression provides specialized types for different algorithms and archive formats.

    • Use Deflate.decompress(data:) for raw deflated data.
    • Use GzipArchive.unarchive(archive:) for GZip archives, as raw deflated data is rarely encountered outside of an archive container.
    // For raw deflated data
    let decompressedData = try? Deflate.decompress(data: data)
    
    // For GZip archives
    let decompressedData = try? GzipArchive.unarchive(archive: data)
  7. Supported algorithms and archive formats

    develop

    SWCompression supports various compression algorithms and archive containers. Note that some features are marked as TBD (planned but not yet implemented).

    Algorithms

    AlgorithmDecompressionCompression
    Deflate✅✅
    BZip2✅✅
    LZMA/LZMA2✅TBD
    LZ4✅✅

    Archives & Containers

    FormatReadWrite
    Zlib✅✅
    GZip✅✅
    XZ✅TBD
    ZIP✅TBD
    TAR✅✅
    7-Zip✅TBD
  8. Available swcomp subcommands

    develop

    The swcomp CLI supports the following command groups:

    • XZCommand: For XZ compression/decompression.
    • LZ4Command: For LZ4 compression/decompression.
    • LZMACommand: For LZMA compression/decompression.
    • BZip2Command: For BZip2 compression/decompression.
    • GZipCommand: For GZip compression/decompression.
    • ZipCommand: For Zip compression/decompression.
    • TarCommand: For Tar archiving.
    • SevenZipCommand: For SevenZip compression/decompression.
    • BenchmarkGroup: A collection of commands for running performance benchmarks.
  9. Use the swcomp CLI for compression and decompression

    develop

    The swcomp command-line tool is a client for the SWCompression framework. It provides subcommands for various compression formats and a benchmarking suite. You can use it to compress or decompress files using formats like XZ, LZ4, LZMA, BZip2, GZip, Zip, Tar, and SevenZip.

    # Example usage (commands depend on specific implementation details of each subcommand)
    swcomp xz [options] <file>
    swcomp zip [options] <file>
    swcomp benchmark [options]