{"id":13872395,"url":"https://github.com/tsolomko/SWCompression","last_synced_at":"2025-07-16T02:30:46.998Z","repository":{"id":12614658,"uuid":"71072507","full_name":"tsolomko/SWCompression","owner":"tsolomko","description":"A Swift framework for working with compression, archives and containers.","archived":false,"fork":false,"pushed_at":"2024-02-08T17:38:40.000Z","size":23084,"stargazers_count":221,"open_issues_count":9,"forks_count":32,"subscribers_count":6,"default_branch":"develop","last_synced_at":"2024-03-14T22:39:39.756Z","etag":null,"topics":["7-zip","bzip2","compression","deflate","gzip","lz4","lzma","swift","tar","xz","zip","zlib"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tsolomko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-10-16T19:33:23.000Z","updated_at":"2024-04-15T13:34:57.293Z","dependencies_parsed_at":"2022-08-31T03:52:02.323Z","dependency_job_id":"7fccf960-15a5-4ac0-889f-2a371c56663d","html_url":"https://github.com/tsolomko/SWCompression","commit_stats":{"total_commits":2296,"total_committers":5,"mean_commits":459.2,"dds":0.00217770034843201,"last_synced_commit":"1e7393dc54c2ec0a698e6eb1d6b9989624104447"},"previous_names":[],"tags_count":90,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsolomko%2FSWCompression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsolomko%2FSWCompression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsolomko%2FSWCompression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsolomko%2FSWCompression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsolomko","download_url":"https://codeload.github.com/tsolomko/SWCompression/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226095753,"owners_count":17572980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["7-zip","bzip2","compression","deflate","gzip","lz4","lzma","swift","tar","xz","zip","zlib"],"created_at":"2024-08-05T23:00:41.542Z","updated_at":"2025-07-16T02:30:46.989Z","avatar_url":"https://github.com/tsolomko.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# SWCompression\n\n[![Swift 5.7+](https://img.shields.io/badge/Swift-5.7+-blue.svg)](https://developer.apple.com/swift/)\n[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/tsolomko/SWCompression/master/LICENSE)\n[![Build Status](https://dev.azure.com/tsolomko/SWCompression/_apis/build/status/tsolomko.SWCompression?branchName=develop)](https://dev.azure.com/tsolomko/SWCompression/_build/latest?definitionId=3\u0026branchName=develop)\n\nA framework with (de)compression algorithms and functions for working with various archives and containers.\n\n## What is this?\n\nSWCompression is a framework with a collection of functions for:\n\n1. Decompression (and sometimes compression) using different algorithms.\n2. Reading (and sometimes writing) archives of different formats.\n3. Reading (and sometimes writing) containers such as ZIP, TAR and 7-Zip.\n\nIt also works on Apple platforms, Linux, __and Windows__.\n\nAll features are listed in the tables below. \"TBD\" means that feature is planned but not implemented (yet).\n\n|               | Deflate | BZip2 | LZMA/LZMA2 | LZ4 |\n| ------------- | ------- | ----- | ---------- | --- |\n| Decompression | ✅      | ✅     | ✅         | ✅  |\n| Compression   | ✅      | ✅     | TBD        | ✅  |\n\n|       | Zlib | GZip | XZ  | ZIP | TAR | 7-Zip |\n| ----- | ---- | ---- | --- | --- | --- | ----- |\n| Read  | ✅   | ✅    | ✅  | ✅  | ✅   | ✅    |\n| Write | ✅   | ✅    | TBD | TBD | ✅   | TBD   |\n\nAlso, SWCompression is _written with Swift only._\n\n## Installation\n\nSWCompression can be integrated into your project using Swift Package Manager, CocoaPods, or Carthage.\n\n### Swift Package Manager\n\nTo install using SPM, add SWCompression to you package dependencies and specify it as a dependency for your target, e.g.:\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n    name: \"PackageName\",\n    dependencies: [\n        .package(name: \"SWCompression\", url: \"https://github.com/tsolomko/SWCompression.git\",\n                 from: \"4.8.0\")\n    ],\n    targets: [\n        .target(\n            name: \"TargetName\",\n            dependencies: [\"SWCompression\"]\n        )\n    ]\n)\n```\n\nMore details you can find in [Swift Package Manager's Documentation](https://github.com/apple/swift-package-manager/tree/main/Documentation).\n\n### CocoaPods\n\nAdd `pod 'SWCompression', '~\u003e 4.8'` and `use_frameworks!` lines to your Podfile.\n\nTo complete installation, run `pod install`.\n\nIf you need only some parts of framework, you can install only them using sub-podspecs. Available subspecs:\n\n- SWCompression/BZip2\n- SWCompression/Deflate\n- SWCompression/Gzip\n- SWCompression/LZMA\n- SWCompression/LZMA2\n- SWCompression/LZ4\n- SWCompression/SevenZip\n- SWCompression/TAR\n- SWCompression/XZ\n- SWCompression/Zlib\n- SWCompression/ZIP\n\n#### \"Optional Dependencies\"\n\nFor both ZIP and 7-Zip there is the most commonly used compression method: Deflate and LZMA/LZMA2 correspondingly. Thus,\nSWCompression/ZIP subspec has SWCompression/Deflate subspec as a dependency and SWCompression/LZMA subspec is a\ndependency for SWCompression/SevenZip.\n\nBut both of these formats also support other compression methods, and some of them are implemented in SWCompression.\nFor CocoaPods configurations there are some sort of 'optional dependencies' for such compression methods.\n\n\"Optional dependency\" in this context means that SWCompression/ZIP or SWCompression/7-Zip will support a compression\nmethod only if a corresponding subspec is expicitly specified in your Podfile and installed.\n\nList of \"optional dependecies\":\n\n- For SWCompression/ZIP:\n    - SWCompression/BZip2\n    - SWCompression/LZMA\n- For SWCompression/SevenZip:\n    - SWCompression/BZip2\n    - SWCompression/Deflate\n    - SWCompression/LZ4\n\n__Note:__ If you use Swift Package Manager or Carthage you always have everything (ZIP and 7-Zip are built with Deflate,\nBZip2, LZMA/LZMA2 and LZ4 support).\n\n### Carthage\n\nAdd to your Cartfile `github \"tsolomko/SWCompression\" ~\u003e 4.8`.\n\nThen you should run `carthage update --use-xcframeworks`. After that drag and drop both `SWCompression.xcframework` and\n`BitByteData.xcframework` files from from the `Carthage/Build/` directory into the \"Frameworks, Libraries, and Embedded\nContent\" section of your target's \"General\" tab in Xcode.\n\n## Usage\n\n### Basic Example\n\nFor example, if you want to decompress \"deflated\" data just use:\n\n```swift\n// let data = \u003cYour compressed data\u003e\nlet decompressedData = try? Deflate.decompress(data: data)\n```\n\nHowever, it is unlikely that you will encounter deflated data outside of any archive. So, in the case of GZip archive\nyou should use:\n\n```swift\nlet decompressedData = try? GzipArchive.unarchive(archive: data)\n```\n\n### Handling Errors\n\nMost SWCompression functions can throw errors and you are responsible for handling them. If you look at the list of\navailable error types and their cases, you may be frightened by their number. However, most of the cases (such as\n`XZError.wrongMagic`) exist for diagnostic purposes.\n\nThus, you only need to handle the most common type of error for your archive/algorithm. For example:\n\n```swift\ndo {\n    // let data = \u003cYour compressed data\u003e\n    let decompressedData = try XZArchive.unarchive(archive: data)\n} catch let error as XZError {\n    // \u003chandle XZ related error here\u003e\n} catch let error {\n    // \u003chandle all other errors here\u003e\n}\n```\n\n### Documentation\n\nEvery function or type of SWCompression's public API is documented. This documentation can be found at its own\n[website](http://tsolomko.github.io/SWCompression) or via a slightly shorter link:\n[swcompression.tsolomko.me](http://swcompression.tsolomko.me)\n\n### Sophisticated example\n\nThere is a small command-line program, \"swcomp\", which is included in this repository in \"Sources/swcomp\". It can be\nbuilt using Swift Package Manager (only available on macOS).\n\n__IMPORTANT:__ The \"swcomp\" command-line tool is NOT intended for general use.\n\n## Contributing\n\nWhether you find a bug, have a suggestion, idea, feedback or something else, please\n[create an issue](https://github.com/tsolomko/SWCompression/issues) on GitHub. If you have any questions, you can ask\nthem on the [Discussions](https://github.com/tsolomko/SWCompression/discussions) page.\n\nIn the case of a bug, it will be especially helpful if you attach a file (archive, etc.) that caused the bug to occur.\n\nIf you'd like to contribute, please [create a pull request](https://github.com/tsolomko/SWCompression/pulls) on GitHub.\n\n__Note:__ If you are considering working on SWCompression, please note that Xcode project (SWCompression.xcodeproj)\nwas created manually and you shouldn't use `swift package generate-xcodeproj` command.\n\n### Executing tests locally\n\nIf you want to run tests on your computer, you need to do a couple of additional steps after cloning the repository:\n\n```bash\n./utils.py download-bbd-macos\ngit submodule update --init --recursive\ncd \"Tests/Test Files\"\ncp gitattributes-copy .gitattributes\ngit lfs pull\ngit lfs checkout\n```\n\nThe first command will download the BitByteData dependency, which requires having Carthage installed. The remaining\ncommands will download the files used in tests. These files are stored in a\n[separate repository](https://github.com/tsolomko/SWCompression-Test-Files), using Git LFS. There are two reasons for\nthis complicated setup. Firstly, some of these files can be quite big, and it would be unfortunate if the users of\nSWCompression had to download them during the installation. Secondly, Swift Package Manager and contemporary versions of\nXcode don't always work well with git-lfs-enabled repositories. To prevent any potential problems test files were moved\ninto another repository.\n\nPlease note, that if you want to add a new _type_ of test files, in addition to running `git lfs track`, you have to\nalso copy into the \"Tests/Test Files/gitattributes-copy\" file a line this command adds to the \"Tests/Test Files/.gitattributes\"\nfile. __Do not commit the \".gitattributes\" file to the git history. It is git-ignored for a reason!__\n\nPlease also be mindful of Git LFS bandwidth quota on GitHub: try to limit downloading lfs'd files using `git lfs pull`.\nIn CI we use some caching techniques to help with the quota, so if you're going to add new tests that require several\nnew test files you should try to submit them all together to reduce the amount of times CI needs to recreate the cache\n(recreating the cache requires to do `git lfs pull` for all test files).\n\n## Performance\n\nUsing whole module optimizations is recommended for the best performance. They are enabled by default in the Release build\nconfiguration.\n\n[Tests Results](Tests/Results.md) document contains results of benchmarking of various functions.\n\n## Why?\n\nFirst of all, existing solutions for working with compression, archives and containers have certain disadvantages. They\nmight not support a particular compression algorithm or archive format and they all have different APIs, which sometimes\ncan be slightly confusing for users, especially when you mix different libraries in one project. This project attempts to\nprovide missing (and sometimes existing) functionality through the unified API which is easy to use and remember.\n\nSecondly, in some cases it may be important to have a compression framework written entirely in Swift, without relying\non either system libraries or solutions implemented in other languages. Additionaly, since SWCompression is written\ncompletely in Swift without Objective-C, it can also be used on Linux, __and Windows__.\n\n## Future plans\n\n- Performance...\n- Better Deflate compression.\n- Something else...\n\n## License\n\n[MIT licensed](LICENSE)\n\n## References\n\n- [pyflate](http://www.paul.sladen.org/projects/pyflate/)\n- [Deflate specification](https://www.ietf.org/rfc/rfc1951.txt)\n- [GZip specification](https://www.ietf.org/rfc/rfc1952.txt)\n- [Zlib specification](https://www.ietf.org/rfc/rfc1950.txt)\n- [LZMA SDK and specification](http://www.7-zip.org/sdk.html)\n- [XZ specification](http://tukaani.org/xz/xz-file-format-1.0.4.txt)\n- [Wikipedia article about LZMA](https://en.wikipedia.org/wiki/Lempel–Ziv–Markov_chain_algorithm)\n- [.ZIP Application Note](http://www.pkware.com/appnote)\n- [ISO/IEC 21320-1](http://www.iso.org/iso/catalogue_detail.htm?csnumber=60101)\n- [List of defined ZIP extra fields](https://opensource.apple.com/source/zip/zip-6/unzip/unzip/proginfo/extra.fld)\n- [Wikipedia article about TAR](https://en.wikipedia.org/wiki/Tar_(computing))\n- [Pax specification](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html)\n- [Basic TAR specification](https://www.gnu.org/software/tar/manual/html_node/Standard.html)\n- [star man pages](https://www.systutorials.com/docs/linux/man/5-star/)\n- [Apache Commons Compress](https://commons.apache.org/proper/commons-compress/)\n- [A walk through the SA-IS Suffix Array Construction Algorithm](http://zork.net/~st/jottings/sais.html)\n- [Wikipedia article about BZip2](https://en.wikipedia.org/wiki/Bzip2)\n- [LZ4 Frame Format Description](https://github.com/lz4/lz4/blob/dev/doc/lz4_Frame_format.md)\n- [LZ4 Block Format Description](https://github.com/lz4/lz4/blob/dev/doc/lz4_Block_format.md)\n- [xxHash specification](https://github.com/Cyan4973/xxHash/blob/dev/doc/xxhash_spec.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsolomko%2FSWCompression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsolomko%2FSWCompression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsolomko%2FSWCompression/lists"}