GithubHelp home page GithubHelp logo

jrjohn / swiftfoundationcompression Goto Github PK

View Code? Open in Web Editor NEW

This project forked from benspratling4/swiftfoundationcompression

0.0 0.0 0.0 57 KB

Foundation-oriented Swift wrapper for zlib

Swift 100.00%

swiftfoundationcompression's Introduction

SwiftFoundationCompression

Introduction

This package wraps file & data compression behavior available in zlib with Swift wrappers written to feel at home with the Foundation module. No UnsafePointers, no file descriptors, no String paths. This behavior is available in 3 levels:

  • Working with Data. Behavior is designed to work with data small enough to be entirely loaded in RAM, but is optimized to read mapped Data.

  • Working with files at URLs, use the FileManager extensions. Methods are provided for compressing a directory into a file

  • Representing a .zip or .tar.gz file as an in-ram file/folder structure with ZipDirectoryWrapping (similar to a directory FileWrapper). Individual files in the .zip file conform to DataWrapping (a SwiftPatterns protocol similar to Foundation's FileWrapper). For .zip files, each individual file is not decompressed until it is accessed.

Status

Rudimentary .zip file opening, reading, and inflate have been implemented. Optimized file writing is not implemented.

.gzip read has been implemented.

Data

Compress or uncompress a Data with .compressed(using:progress:) (or .decompressed(using:progress:)), optionally choosing to use .gzip instead of .deflate.

Data compression with .deflate does not generate a header., and decompression works on the stream after the header. Data compression with gzip generates a header, suitable for wrapping, and requires the wrapper when uncompressing.

FileManager

To decompress a number of existing files, use FileManager.

func decompress(item:, with:, into:progress:)

which opens a compressed file and expands its contents into the supplied directory.

Compressed on disk / file/folder in RAM

For file formats which exist as zipped on disk, but structured file/folders in RAM, something akin to "zipped" FileWrapper would be nice. FileWrapper has a design problem: both directories and regular files are the same class, meaning the API's are not compilar-enforced. Using the SerializedResourceWrapping protocol from the SwiftPatterns module, this module introduces the ZipDirectoryWrapping class, which conforms to the SubResourceWrapping protocol. You can browse it similarly to a directory FileWrapper, but individual files (which conform to DataWrapping) are not decompressed until you access the .contents property on them (for .zip files).

Optimizations

Data methods access data in page-sized groups to reduce dirty memory footprint, but no optimization is made for the output data. You should only use this for data you know to be useful in memory.

Not yet implemented: FileManager methods make use of the page-size mapping of Data, and FileHandles to write as if it were a stream.

Contributions

There are many corners with compression. If you'd like to contribute, fork it, write it, and make a PR.

Here are some non-goals:

  • Supporting more CRC. Detecting error storage/transmission errors should be provided by the data storage & transmision layer. It is not suitable for the internal contents of a file.

  • Supporting encryption. Nowadays, encryption is facilitated by the device for the filesystem as a whole. It is not suitable for the internal contents of a file, except under exceptional cirucmstances.

swiftfoundationcompression's People

Contributors

benspratling4 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.