Crates.io | zopen |
lib.rs | zopen |
version | 1.0.0 |
source | src |
created_at | 2018-09-26 12:06:25.479976 |
updated_at | 2024-01-17 09:23:43.198752 |
description | Automatically open compressed files. |
homepage | https://chiselapp.com/user/fifr/repository/zopen |
repository | https://chiselapp.com/user/fifr/repository/zopen |
max_upload_size | |
id | 86620 |
size | 23,612 |
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.
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)?;
Frank Fischer frank-fischer@shadow-soft.de
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.
See docs.rs.
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)?;
Source code of latest tagged version: zopen-v1.0.0.tar.gz
Source code of trunk: zopen-trunk.tar.gz