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 theflate2
crate. If disabled, uses the externalgzip
command line tool.bzip2
: enables bzip2 compression through thebzip2
crate. If disabled, uses the externalbzip2
command line tool.xz
: enables xz compression through therust-lzma
crate. If disabled, uses the externalxz
command line tool.zstd
: enables zstd compression through thezstd
crate. If disabled, uses the externalzstd
command 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)?;
Functions
- Open a possibly compressed file for reading.
- Open a possibly compressed file for writing.