Yo!
I am happy to announce the first release of ozstd library! The is a small, modern OCaml binding to Zstandard. It wraps the common one-shot and streaming C APIs in a simple, idiomatic interface.
Features
- One-shot and streaming compression/decompression for strings and bigstrings.
- Reusable compression and decompression contexts.
- Low-level
StreamAPI for manual buffers, and high-levelStateAPI for slice handling.
This is a hard fork of the unmaintained zstd OCaml bindings. It has been fully rewritten and is released separately because the original maintainers do not merge pull requests.
The main goal of creating this library was to provide a way to incrementally compress and decompress features for my Bytream library, which is used in my other library, Rpmfile, to decode a package’s payload as a compressed cpio archive.
However, for regular use, you can use the one-shot API.
let source =
"Contrary to popular belief, Lorem Ipsum is not simply random text."
let compressed =
Ozstd.Compressor.compress_string ~level:3 source
let decompressed =
Ozstd.Decompressor.decompress_string compressed
Or also streaming API (the State module is the high-level API: feed it input slices and emit output slices).
let compress_sequence_into_channel seq oc =
let state = Ozstd.Compressor.State.create () in
let output Slice.{ buf; off; len } =
Out_channel.output_bigarray oc buf off len
in
let aux slice =
Ozstd.Compressor.State.feed state slice `Continue |> output
in
Seq.iter aux seq;
Ozstd.Compressor.State.finish state |> output
An example of usage in the Bytream context.
let uncompressed_payload =
Rpmfile.Payload.to_incoming_bytes compressed_payload
|> Bytream_zstd.In.of_stream
in
For more details see README and other docs.
Limitations. These bindings cover a large part of the Zstandard C API, but not all of it! Pull requests are welcome.
If you encounter any issue with these releases, please report it on the github repository.
Feedback and contributions are welcome.