All Projects → tsolomko → Swcompression

tsolomko / Swcompression

Licence: mit
A Swift framework for working with compression, archives and containers.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swcompression

Archiver
Easily create & extract archives, and compress & decompress files of various formats
Stars: ✭ 3,373 (+2966.36%)
Mutual labels:  zip, tar, gzip
Zippy
Pure Nim implementation of deflate, zlib, gzip and zip.
Stars: ✭ 88 (-20%)
Mutual labels:  zip, zlib, gzip
Bit7z
A C++ static library offering a clean and simple interface to the 7-zip DLLs.
Stars: ✭ 159 (+44.55%)
Mutual labels:  zip, tar, gzip
Libarchivejs
Archive library for browsers
Stars: ✭ 145 (+31.82%)
Mutual labels:  zip, tar, gzip
zzlib
zlib-compressed file depacking library in Lua
Stars: ✭ 44 (-60%)
Mutual labels:  gzip, zip, zlib
Datacompression
Swift libcompression wrapper as an extension for the Data type (GZIP, ZLIB, LZFSE, LZMA, LZ4, deflate, RFC-1950, RFC-1951, RFC-1952)
Stars: ✭ 191 (+73.64%)
Mutual labels:  zip, zlib, gzip
ratarmount
Random Access Read-Only Tar Mount
Stars: ✭ 217 (+97.27%)
Mutual labels:  gzip, zip, tar
Turbobench
Compression Benchmark
Stars: ✭ 211 (+91.82%)
Mutual labels:  zip, zlib, gzip
compress
compress and uncompress for Deno
Stars: ✭ 29 (-73.64%)
Mutual labels:  gzip, zip, tar
Unifiedarchive
UnifiedArchive - an archive manager with a unified way for different formats. Supports all basic (listing, reading, extracting and creation) and specific features (compression level, password-protection). Bundled with console program for working with archives.
Stars: ✭ 246 (+123.64%)
Mutual labels:  zip, tar, gzip
Sharpcompress
SharpCompress is a fully managed C# library to deal with many compression types and formats.
Stars: ✭ 1,397 (+1170%)
Mutual labels:  zip, tar, gzip
zipstream
A command line tool that allows you to easily share files and directories over the network
Stars: ✭ 49 (-55.45%)
Mutual labels:  gzip, zip, tar
Leanify
lightweight lossless file minifier/optimizer
Stars: ✭ 694 (+530.91%)
Mutual labels:  zip, tar, gzip
lzbase62
LZ77(LZSS) based compression algorithm in base62 for JavaScript.
Stars: ✭ 38 (-65.45%)
Mutual labels:  zip, zlib
uncompress.js
Uncompress ZIP, RAR, and TAR files with pure JavaScript
Stars: ✭ 79 (-28.18%)
Mutual labels:  zip, tar
Compressing
Everything you need for compressing and uncompressing
Stars: ✭ 268 (+143.64%)
Mutual labels:  tar, gzip
python-isal
Faster zlib and gzip compatible compression and decompression by providing python bindings for the isa-l library.
Stars: ✭ 21 (-80.91%)
Mutual labels:  gzip, zlib
Decompress
Extracting archives made easy
Stars: ✭ 316 (+187.27%)
Mutual labels:  zip, tar
Universal Zopfli Js
JavaScript binding to Zopfli with WebAssembly.
Stars: ✭ 70 (-36.36%)
Mutual labels:  zlib, gzip
Gzipswift
Swift framework that enables gzip/gunzip Data using zlib
Stars: ✭ 356 (+223.64%)
Mutual labels:  zlib, gzip

SWCompression

Swift 4.2 Swift 5.X GitHub license Build Status Build Status

A framework with (de)compression algorithms and functions for working with various archives and containers.

What is this?

SWCompression — is a framework with a collection of functions for:

  1. Decompression (and sometimes compression) using different algorithms.
  2. Reading (and sometimes writing) archives of different formats.
  3. Reading (and sometimes writing) containers such as ZIP, TAR and 7-Zip.

It also works both on Apple platforms and Linux.

All features are listed in the tables below. "TBD" means that feature is planned but not implemented (yet).

Deflate BZip2 LZMA/LZMA2
Decompression
Compression TBD
Zlib GZip XZ ZIP TAR 7-Zip
Read
Write TBD TBD TBD

Also, SWCompression is written with Swift only.

Installation

SWCompression can be integrated into your project using Swift Package Manager, CocoaPods or Carthage.

Swift Package Manager

To install using SPM, add SWCompression to you package dependencies and specify it as a dependency for your target, e.g.:

import PackageDescription

let package = Package(
    name: "PackageName",
    dependencies: [
        .package(url: "https://github.com/tsolomko/SWCompression.git",
                 from: "4.5.0")
    ],
    targets: [
        .target(
            name: "TargetName",
            dependencies: ["SWCompression"]
        )
    ]
)

More details you can find in Swift Package Manager's Documentation.

CocoaPods

Add pod 'SWCompression', '~> 4.5' and use_frameworks! lines to your Podfile.

To complete installation, run pod install.

If you need only some parts of framework, you can install only them using sub-podspecs. Available subspecs:

  • SWCompression/BZip2
  • SWCompression/Deflate
  • SWCompression/Gzip
  • SWCompression/LZMA
  • SWCompression/LZMA2
  • SWCompression/SevenZip
  • SWCompression/TAR
  • SWCompression/XZ
  • SWCompression/Zlib
  • SWCompression/ZIP

"Optional Dependencies"

For both ZIP and 7-Zip there is the most commonly used compression method: Deflate and LZMA/LZMA2 correspondingly. Thus, SWCompression/ZIP subspec has SWCompression/Deflate subspec as a dependency and SWCompression/LZMA subspec is a dependency for SWCompression/SevenZip.

But both of these formats also support other compression methods, and some of them are implemented in SWCompression. For CocoaPods configurations there are some sort of 'optional dependencies' for such compression methods.

"Optional dependency" in this context means that SWCompression/ZIP or SWCompression/7-Zip will support a compression method only if a corresponding subspec is expicitly specified in your Podfile and installed.

List of "optional dependecies":

  • For SWCompression/ZIP:
    • SWCompression/BZip2
    • SWCompression/LZMA
  • For SWCompression/SevenZip:
    • SWCompression/BZip2
    • SWCompression/Deflate

Note: If you use Swift Package Manager or Carthage you always have everything (ZIP and 7-Zip are built with Deflate, BZip2 and LZMA/LZMA2 support).

Carthage

Important: Only Swift 5.x is supported when installing SWCompression via Carthage.

Add to your Cartfile github "tsolomko/SWCompression" ~> 4.5.

Then run carthage update.

Finally, drag and drop SWCompression.framework from the Carthage/Build directory into the "Embedded Binaries" section on your targets' "General" tab in Xcode.

SWCompression uses BitByteData framework, so Carthage will also download it, and you should put the BitByteData.framework file into the "Embedded Binaries" as well.

Usage

Basic Example

For example, if you want to decompress "deflated" data just use:

// let data = <Your compressed data>
let decompressedData = try? Deflate.decompress(data: data)

However, it is unlikely that you will encounter deflated data outside of any archive. So, in the case of GZip archive you should use:

let decompressedData = try? GzipArchive.unarchive(archive: data)

Handling Errors

Most SWCompression functions can throw errors and you are responsible for handling them. If you look at the list of available error types and their cases, you may be frightened by their number. However, most of the cases (such as XZError.wrongMagic) exist for diagnostic purposes.

Thus, you only need to handle the most common type of error for your archive/algorithm. For example:

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>
}

Documentation

Every function or type of SWCompression's public API is documented. This documentation can be found at its own website.

Sophisticated example

There is a small command-line program, "swcomp", which is included in this repository in "Sources/swcomp". To build it you need to uncomment several lines in "Package.swift" and run swift build -c release.

Contributing

Whether you find a bug, have a suggestion, idea, feedback or something else, please create an issue on GitHub.

In the case of a bug, it will be especially helpful if you attach a file (archive, etc.) that caused the bug to occur.

If you'd like to contribute, please create a pull request on GitHub.

Note: If you are considering working on SWCompression, please note that Xcode project (SWCompression.xcodeproj) was created manually and you shouldn't use swift package generate-xcodeproj command.

Executing tests locally

If you want to run tests on your computer, you need to do an additional step after cloning the repository:

./utils.py prepare-workspace {macos|other}

The argument of this function is an operating system that you're using. This command will download files used in tests, and on macOS it will also try to download BitByteData dependency, which requires having Carthage installed.

Test files are stored in a separate repository, using Git LFS. There are two reasons for this complicated setup. Firstly, some of these files can be quite big, and it would be unfortunate if the users of SWCompression had to download them every time during the installation. Secondly, Swift Package Manager and contemporary versions of Xcode don't always work well with git-lfs-enabled repositories. To prevent any potential problems test files were moved into another repository. Additionaly, the custom command line tool utils.py is used to work around issues occuring on certain user systems (see, for example, #9).

Please note, that if you want to add a new type of test files, in addition to running git lfs track, you have to also copy into the "Tests/Test Files/gitattributes-copy" file a line this command adds to the "Tests/Test Files/.gitattributes" file. Do not commit the ".gitattributes" file to the git history. It is git-ignored for a reason!

Performance

Using whole module optimizations is recommended for the best performance. They are enabled by default in the Release build configuration.

Tests Results document contains results of benchmarking of various functions.

Why?

First of all, existing solutions for working with compression, archives and containers have certain disadvantages. They might not support a particular compression algorithm or archive format and they all have different APIs, which sometimes can be slightly confusing for users, especially when you mix different libraries in one project. This project attempts to provide missing (and sometimes existing) functionality through the unified API which is easy to use and remember.

Secondly, in some cases it may be important to have a compression framework written entirely in Swift, without relying on either system libraries or solutions implemented in other languages. Additionaly, since SWCompression is written completely in Swift without Objective-C, it can also be used on Linux.

Future plans

See 5.0 Update Project for the list of planned API changes and new features.

  • Performance...
  • Better Deflate compression.
  • Something else...

License

MIT licensed

References

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].