Compressed bytes, bzip2 streams for bytesrw
README.md

bytesrw-bz2 #

Bzip2 compressed streams for bytesrw, using the libbz2 C library.

Source archives and older datasets are still distributed as .bz2 files. Bytesrw_bz2 provides bytesrw reader and writer filters that compress and decompress bzip2 streams through the libbz2 C library. The filters have the same shape as those of the bytesrw.zlib and bytesrw.zstd libraries: decompress_reads, decompress_writes, compress_reads and compress_writes. Concatenated streams decode as the bzip2 tool decodes appended files, and in single-stream mode the wrapped reader is left positioned on the bytes after the stream.

Installation #

$ opam install bytesrw-bz2   # requires the libbz2 C library

If opam cannot find the package, it may not yet be released in the public opam-repository. Add the overlay repository, then install it:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install bytesrw-bz2

Usage #

Compress a string and decompress it back:

# open Bytesrw;;
# let data = String.concat " " (List.init 100 string_of_int) in
  let bz = Bytes.Reader.filter_string [ Bytesrw_bz2.compress_reads () ] data in
  let back = Bytes.Reader.filter_string [ Bytesrw_bz2.decompress_reads () ] bz in
  back = data && String.length bz < String.length data;;
- : bool = true

Licence #

ISC. See LICENSE.md.