Crate bgzf

source · []
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.


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);


Level of compression to use for for the compressors.

Compressor will BGZF compress a block of bytes with the Compressor::compress method, allowing for reuse of the compressor itself.

A BGZF reader.

A BGZF writer.



The maximum uncompressed blocksize for BGZF compression (taken from bgzip), used for initializing blocks.

128 KB default buffer size, same as pigz.