zopen  zopen

rs-graph crate zopen docs

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