#lzma #encoding #api-bindings

xz

Rust bindings to liblzma providing Read/Write streams as well as low-level in-memory encoding/decoding. Alias of xz2 crate

2 unstable releases

0.1.0 Aug 17, 2020
0.0.1 Feb 12, 2015

#391 in Compression

Download history 3979/week @ 2024-08-15 4275/week @ 2024-08-22 4384/week @ 2024-08-29 5453/week @ 2024-09-05 5232/week @ 2024-09-12 4456/week @ 2024-09-19 3543/week @ 2024-09-26 3390/week @ 2024-10-03 4536/week @ 2024-10-10 6181/week @ 2024-10-17 5538/week @ 2024-10-24 4703/week @ 2024-10-31 6378/week @ 2024-11-07 4892/week @ 2024-11-14 5733/week @ 2024-11-21 9355/week @ 2024-11-28

27,356 downloads per month
Used in 59 crates (24 directly)

MIT/Apache

77KB
1K SLoC

xz-rs crate version

A streaming compression/decompression library for Rust with bindings to liblzma. It's currently an alias of xz2 crate. See documentation for the further details.

[dependencies]
xz = "0.1"

 


xz-rs is primarily distributed under the terms of both the Apache License (Version 2.0) and the MIT license. See COPYRIGHT for details.


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 xz::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:

xz = { version = "0.1", 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.

Remark

Currently, xz crate is an alias of xz2 crate.

Dependencies

~2MB
~43K SLoC