bgzf 0.4.0

Utility library for working with explicitly BGZF compressed data
Documentation

bgzf

This library provides both high level readers and writers for the BGZF format as well as lower level compressor and decompressor functions.

Bgzf is a multi-gzip format that adds an extra field to the header indicating how large the complete block (with header and footer) is.

Visit us at Fulcrum Genomics to learn more about how we can power your Bioinformatics with bgzf and beyond.

Documentation and Examples

Please see the generated Rust Docs.

Multithreading

The default Reader/Writer are single-threaded. Enable the optional multithreading-simple feature to also get MultithreadedReader and MultithreadedWriter, which (de)compress blocks in parallel on a dedicated pool of worker threads while preserving block order:

[dependencies]
bgzf = { version = "0.4", features = ["multithreading-simple"] }
use std::fs::File;
use std::num::NonZero;
use bgzf::MultithreadedReader;

// The inner reader is any `Read + Send + 'static` source — here, a BGZF file on disk.
let input = File::open("example.bgzf")?;
let reader = MultithreadedReader::with_worker_count(NonZero::new(4).unwrap(), input);

Each reader/writer owns its own worker threads (hence simple), as distinguished from a future multithreading-pooled feature that would share one thread pool across many instances. Read-ahead/write-ahead depth is decoupled from the worker count, so even a single-worker instance pipelines rather than stalling. Decompressed output is byte-identical to Reader, and compressed output is byte-identical to Writer, at every worker count.

Benchmarks

Run the compression benchmarks with:

cargo bench

This runs Criterion benchmarks measuring:

  • Single block compression at various levels
  • Writer throughput
  • Reader throughput and read/write round-trips (including store-only)

The multithreaded reader/writer benchmarks (single-threaded vs. 1/2/4 workers) require the feature:

cargo bench --features multithreading-simple --bench multithreaded