Skip to main content

Crate bgzf

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.

§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§

CompressionLevel
Level of compression to use for for the compressors.
Compressor
Compressor will BGZF compress a block of bytes with the Compressor::compress method, allowing for reuse of the compressor itself.
MultithreadedReadermultithreading-simple
A multithreaded BGZF reader.
MultithreadedWritermultithreading-simple
A multithreaded BGZF writer.
Reader
A BGZF reader.
Writer
A BGZF writer.

Enums§

BgzfError

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.