Expand description
Simple crate that automatically open compressed files.
The compressor used is determined by the file extension. If the corresponding compression library is not available (i.e. the corresponding feature is not activated), the crate tries to use an external compression tool (gzip, bzip2, xz or zstd).
The crate exports two functions read and [write]. Given a file path,
they return a Box<Read> or a Box<Write>, respectively, accessing the file.
Depending on the file extension, the file is filtered through an appropriate
compressor/decompressor.
§Features
The following features enable compression/decompression through external
crates. If a features is disabled, zopen uses the corresponding command line tool
instead.
gzip: enables gzip compression through theflate2crate. If disabled, uses the externalgzipcommand line tool.bzip2: enables bzip2 compression through thebzip2crate. If disabled, uses the externalbzip2command line tool.xz: enables xz compression through therust-lzmacrate. If disabled, uses the externalxzcommand line tool.zstd: enables zstd compression through thezstdcrate. If disabled, uses the externalzstdcommand line tool.all: enabled all of above.
§Example
Reading a compressed file:
let mut f = zopen::read("test.file.gz")?; // open gzip compressed file.
let mut data = String::new();
f.read_to_string(&mut data)?;Writing to a compressed file:
let mut f = zopen::write("test.file.zst")?; // create zstd compressed file.
writeln!(f, "{}: {}", "Hello world", 42)?;