Expand description
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.
§Examples
use bgzf::{Reader, Writer};
use std::error::Error;
use std::io;
/// Contrived example that decompresses stdin and compresses to stdout.
fn main() -> Result<(), Box<dyn Error>> {
let mut reader = Reader::new(io::stdin());
let mut writer = Writer::new(io::stdout(), 2.try_into()?);
let total_bytes = io::copy(&mut reader, &mut writer)?;
eprintln!("{} uncompressed bytes", total_bytes);
Ok(())
}§Multithreading
The Reader and Writer above are single-threaded. Enabling the optional
multithreading-simple feature adds MultithreadedReader and MultithreadedWriter, which
(de)compress blocks in parallel on a dedicated pool of worker threads while preserving block
order, exposing the same std::io::Read/std::io::Write interfaces. Each reader/writer
owns its own worker threads — hence simple — as distinguished from a possible future
multithreading-pooled feature that would share one thread pool across many readers/writers.
Structs§
- Compression
Level - Level of compression to use for for the compressors.
- Compressor
Compressorwill BGZF compress a block of bytes with theCompressor::compressmethod, allowing for reuse of the compressor itself.- Multithreaded
Reader multithreading-simple - A multithreaded BGZF reader.
- Multithreaded
Writer multithreading-simple - A multithreaded BGZF writer.
- Reader
- A BGZF reader.
- Writer
- A BGZF writer.
Enums§
Constants§
- BGZF_
BLOCK_ SIZE - The maximum uncompressed blocksize for BGZF compression (taken from bgzip), used for initializing blocks.
- BUFSIZE
- 128 KB default buffer size, same as pigz.