All Projects → mirage → decompress

mirage / decompress

Licence: MIT License
Pure OCaml implementation of Zlib.

Programming Languages

ocaml
1615 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to decompress

power-gzip
POWER9 gzip engine documentation and code samples
Stars: ✭ 16 (-84.47%)
Mutual labels:  compression, zlib, decompression, deflate
raisin
A simple lightweight set of implementations and bindings for compression algorithms written in Go.
Stars: ✭ 17 (-83.5%)
Mutual labels:  compression, huffman, decompression
Fflate
High performance (de)compression in an 8kB package
Stars: ✭ 547 (+431.07%)
Mutual labels:  compression, zlib, decompression
EasyCompressor
⚡ A compression library that implements many compression algorithms such as LZ4, Zstd, LZMA, Snappy, Brotli, GZip, and Deflate. It helps you to improve performance by reducing Memory Usage and Network Traffic for caching.
Stars: ✭ 167 (+62.14%)
Mutual labels:  compression, decompression, deflate
deflate-rs
An implementation of a DEFLATE encoder in rust
Stars: ✭ 47 (-54.37%)
Mutual labels:  compression, zlib, deflate
em inflate
Fast, small, in-memory inflate (zlib, deflate and gzip decompression)
Stars: ✭ 59 (-42.72%)
Mutual labels:  compression, huffman, zlib
Huffman-Coding
A C++ compression program based on Huffman's lossless compression algorithm and decoder.
Stars: ✭ 81 (-21.36%)
Mutual labels:  compression, huffman, decompression
pyrus-cramjam
Thin Python wrapper to de/compression algorithms in Rust - lightweight & no dependencies
Stars: ✭ 40 (-61.17%)
Mutual labels:  compression, decompression, deflate
kanzi-cpp
Lossless data compression in C++
Stars: ✭ 60 (-41.75%)
Mutual labels:  compression, huffman, lz77
lzbase62
LZ77(LZSS) based compression algorithm in base62 for JavaScript.
Stars: ✭ 38 (-63.11%)
Mutual labels:  compression, zlib, lz77
gpuhd
Massively Parallel Huffman Decoding on GPUs
Stars: ✭ 30 (-70.87%)
Mutual labels:  huffman, decompression
rbzip2
bzip2 for Ruby
Stars: ✭ 39 (-62.14%)
Mutual labels:  compression, decompression
http compression
🗜️ Deno HTTP compression middleware
Stars: ✭ 34 (-66.99%)
Mutual labels:  compression, deflate
zstd-rs
zstd-decoder in pure rust
Stars: ✭ 148 (+43.69%)
Mutual labels:  compression, decompression
zlib
Compression and decompression in the gzip and zlib formats
Stars: ✭ 32 (-68.93%)
Mutual labels:  compression, zlib
zzlib
zlib-compressed file depacking library in Lua
Stars: ✭ 44 (-57.28%)
Mutual labels:  zlib, deflate
mtscomp
Multichannel time series lossless compression in pure Python based on NumPy and zlib
Stars: ✭ 20 (-80.58%)
Mutual labels:  compression, zlib
zpacker
very simple LZ77-based compression
Stars: ✭ 15 (-85.44%)
Mutual labels:  compression, lz77
box
Box - Open Standard Archive Format, a zip killer.
Stars: ✭ 38 (-63.11%)
Mutual labels:  compression, deflate
ZipArchive
A single-class pure VB6 library for zip with ASM speed
Stars: ✭ 38 (-63.11%)
Mutual labels:  compression, zlib

Decompress - Pure OCaml implementation of decompression algorithms

decompress is a library which implements:

The library

The library is available with:

$ opam install decompress

It provides three sub-packages:

  • decompress.de to handle RFC1951 stream
  • decompress.zl to handle Zlib stream
  • decompress.gz to handle Gzip stream
  • decompress.lzo to handle LZO contents

Each sub-package provide 3 sub-modules:

  • Inf to inflate/decompress a stream
  • Def to deflate/compress a stream
  • Higher as a easy entry point to use the stream

How to use it

Link issue

decompress uses checkseum to compute CRC of streams. checkseum provides 2 implementations:

  • a C implementation to be fast
  • an OCaml implementation to be usable with js_of_ocaml (or, at least, require only the caml runtime)

When the user wants to make an OCaml executable, it must choose which implementation of checkseum he wants. A compilation of an executable with decompress.zl is:

$ ocamlfind opt -linkpkg -package checkseum.c,decompress.zl main.ml

Otherwise, the end-user should have a linking error (see #47).

With dune

checkseum uses a mechanism integrated into dune which solves the link issue. It provides a way to silently choose the default implementation of checkseum: checkseum.c.

By this way (and only with dune), an executable with decompress.zl is:

(executable
 (name main)
 (libraries decompress.zl))

Of course, the user still is able to choose which implementation he wants:

(executable
 (name main)
 (libraries checkseum.ocaml decompress.zl))

The API

decompress proposes to the user a full control of:

  • the input/output loop
  • the allocation

Input / Output

The process of the inflation/deflation is non-blocking and it does not require any syscalls (as an usual MirageOS project). The user can decide how to get the input and how to store the output.

An usual loop (which can fit into lwt or async) of decompress.zl is:

let rec go decoder = match Zl.Inf.decode decoder with
  | `Await decoder ->
    let len = input itmp 0 (Bigstringaf.length tmp) in
    go (Zl.Inf.src decoder itmp 0 len)
  | `Flush decoder ->
    let len = Bigstringaf.length otmp - Zl.Inf.dst_rem decoder in
    output stdout otmp 0 len ;
    go (Zl.Inf.flush decoder)
  | `Malformed err -> invalid_arg err
  | `End decoder ->
    let len = Bigstringaf.length otmp - Zl.Inf.dst_rem decoder in
    output stdout otmp 0 len in
go decoder

Allocation

Then, the process does not allocate large objects but it requires at the initialisation these objects. Such objects can be re-used by another inflation/deflation process - of course, these processes can not use same objects at the same time.

val decompress : window:De.window -> in_channel -> out_channel -> unit

let w0 = De.make_windows ~bits:15

(* Safe use of decompress *)
let () =
  decompress ~window:w0 stdin stdout ;
  decompress ~window:w0 (open_in "file.z") (open_out "file")

(* Unsafe use of decompress,
   the second process must use an other pre-allocated window. *)
let () =
  Lwt_main.run @@
    Lwt.join [ (decompress ~window:w0 stdin stdout |> Lwt.return)
             ; (decompress ~window:w0 (open_in "file.z") (open_out "file") |> Lwt.return) ]

This ability can be used on:

  • the input buffer given to the encoder/decoder with src
  • the output buffer given to the encoder/decoder
  • the window given to the encoder/decoder
  • the shared-queue used by the compression algorithm and the encoder

Example

An example exists into bin/main.ml where you can see how to use decompress.zl and decompress.de.

Higher interface

However, decompress provides a higher interface close to what camlzip provides to help newcomers to use decompress:

val compress : refill:(bigstring -> int) -> flush:(bigstring -> int -> unit) -> unit
val uncompress : refill:(bigstring -> int) -> flush:(bigstring -> int -> unit) -> unit

Benchmark

decompress has a benchmark about inflation to see if any update has a performance implication. The process try to inflate a stream and stop at N second(s) (default is 30), The benchmark requires libzlib-dev, cmdliner and bos to be able to compile zpipe and the executable to produce the CSV file. To build the benchmark:

$ dune build --profile benchmark bench/output.csv

On linux machines, /dev/urandom will generate the random input for piping to zpipe. To run the benchmark:

$ cat /dev/urandom | ./build/default/bench/zpipe | ./_build/default/bench/bench.exe

The output file is a CSV file which can be processed by a plot software. It records input bytes, output bytes and memory usage at each second.

Build Requirements

  • OCaml >= 4.07.0
  • dune to build the project
  • base-bytes meta-package
  • bigarray-compat
  • checkseum
  • optint
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].