10 releases (1 stable)
1.0.0 | Jan 17, 2024 |
---|---|
0.6.0 | Jan 9, 2024 |
0.5.0 | Jan 8, 2024 |
0.4.0 | Jan 8, 2024 |
0.3.1 | Sep 26, 2018 |
#143 in Compression
Used in rs-graph
23KB
386 lines
zopen
Introduction
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.
Examples
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)?;
Author
Frank Fischer frank-fischer@shadow-soft.de
Installation
Put the requirement zopen = "^1.0.0"
into the Cargo.toml
of
your project. Optionally, you may enable one (or all
) of the features
(gzip
, bzip2
, xz
, zstd
) to use external crates (instead of command line tools)
for compression.
Documentation
See docs.rs.
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 a compressed file:
let mut f = zopen::write("test.file.zst")?; // create zstd compressed file.
writeln!(f, "{}: {}", "Hello world", 42)?;
Download
Source code of latest tagged version: zopen-v1.0.0.tar.gz
Source code of trunk: zopen-trunk.tar.gz
Dependencies
~0–670KB
~10K SLoC