#xz #io-stream #async-io #lzma #encoding #api-bindings

xz2

Rust bindings to liblzma providing Read/Write streams as well as low-level in-memory encoding/decoding

8 releases

0.1.7 Jun 6, 2022
0.1.6 Oct 11, 2018
0.1.5 May 9, 2018
0.1.4 Dec 31, 2017
0.1.0 Mar 21, 2016

#79 in Compression

Download history 178529/week @ 2024-06-11 191432/week @ 2024-06-18 220262/week @ 2024-06-25 186368/week @ 2024-07-02 184577/week @ 2024-07-09 189503/week @ 2024-07-16 196671/week @ 2024-07-23 202763/week @ 2024-07-30 189313/week @ 2024-08-06 183336/week @ 2024-08-13 187416/week @ 2024-08-20 173264/week @ 2024-08-27 194868/week @ 2024-09-03 169930/week @ 2024-09-10 167230/week @ 2024-09-17 145347/week @ 2024-09-24

700,010 downloads per month
Used in 382 crates (169 directly)

MIT/Apache

2MB
34K SLoC

C 18K SLoC // 0.2% comments PO File 10K SLoC // 0.3% comments Visual Studio Project 2K SLoC Rust 1.5K SLoC // 0.0% comments M4 725 SLoC // 0.4% comments Automake 560 SLoC // 0.2% comments Shell 332 SLoC // 0.3% comments GNU Style Assembly 294 SLoC // 0.4% comments BASH 244 SLoC // 0.3% comments Bitbake 221 SLoC // 0.2% comments Visual Studio Solution 146 SLoC

xz2

Documentation

Bindings to the liblzma implementation in Rust, also provides types to read/write xz streams.

# Cargo.toml
[dependencies]
xz2 = "0.1"

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in xz2 by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

LZMA/XZ encoding and decoding streams

This library is a binding to liblzma currently to provide LZMA and xz encoding/decoding streams. I/O streams are provided in the read, write, and bufread modules (same types, different bounds). Raw in-memory compression/decompression is provided via the stream module and contains many of the raw APIs in liblzma.

Examples

use std::io::prelude::*;
use xz2::read::{XzEncoder, XzDecoder};

// Round trip some bytes from a byte source, into a compressor, into a
// decompressor, and finally into a vector.
let data = "Hello, World!".as_bytes();
let compressor = XzEncoder::new(data, 9);
let mut decompressor = XzDecoder::new(compressor);

let mut contents = String::new();
decompressor.read_to_string(&mut contents).unwrap();
assert_eq!(contents, "Hello, World!");

Async I/O

This crate optionally can support async I/O streams with the Tokio stack via the tokio feature of this crate:

xz2 = { version = "0.1.6", features = ["tokio"] }

All methods are internally capable of working with streams that may return ErrorKind::WouldBlock when they're not ready to perform the particular operation.

Note that care needs to be taken when using these objects, however. The Tokio runtime, in particular, requires that data is fully flushed before dropping streams. For compatibility with blocking streams all streams are flushed/written when they are dropped, and this is not always a suitable time to perform I/O. If I/O streams are flushed before drop, however, then these operations will be a noop.

Dependencies