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:
[]
= { = "0.4", = ["multithreading-simple"] }
use File;
use NonZero;
use MultithreadedReader;
// The inner reader is any `Read + Send + 'static` source — here, a BGZF file on disk.
let input = open?;
let reader = with_worker_count;
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:
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: