8 releases (4 breaking)
0.6.0 | Dec 24, 2023 |
---|---|
0.5.1 | Dec 4, 2023 |
0.4.2 | Nov 16, 2023 |
0.2.2 | Jul 18, 2021 |
0.1.0 | Apr 1, 2020 |
#104 in Compression
1,138 downloads per month
Used in proxy-rs
210KB
4.5K
SLoC
autocompress-rs
Automatically select suitable decoder from magic bytes or encoder from file extension. This library also provides I/O thread pool to perform decompression and compression in background threads.
Supported file formats
- Gzip
- Zlib (Cannot suggest format from magic bytes and file extension)
- BZip2
- XZ
- Z-standard
Feature flags
gzip
: Gzip format supportbgzip
: bgzip format supportbzip2
: Bzip2 format supportxz
: XZ format supportzstd
: Zstd format supportrayon
: Off-load compression and decompression process to another thread using rayontokio
: Async reader and writer support with tokiotokio_fs
: Enableautodetect_async_open
function
Example
Read from a file
use std::io::prelude::*;
use autocompress::autodetect_open;
fn main() -> anyhow::Result<()> {
let mut reader = autodetect_open("testfiles/pg2701.txt.xz")?;
let mut buf = Vec::new();
reader.read_to_end(&mut buf)?;
Ok(())
}
Write to a file
use std::io::prelude::*;
use autocompress::{autodetect_create, CompressionLevel};
fn main() -> anyhow::Result<()> {
let mut writer = autodetect_create("target/doc-index.xz", CompressionLevel::Default)?;
writer.write_all(&b"Hello, world\n"[..])?;
Ok(())
}
Compress file in parallel
use std::io::prelude::*;
use autocompress::{autodetect_parallel_create, CompressionLevel};
fn main() -> anyhow::Result<()> {
let mut writer = autodetect_parallel_create("target/doc-index2.xz", CompressionLevel::Default)?;
writer.write_all(&b"Hello, world\n"[..])?;
Ok(())
}
Dependencies
~0.3–7.5MB
~65K SLoC