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.
- Gzip
- Zlib (Cannot suggest format from magic bytes and file extension)
- BZip2
- XZ
- Z-standard
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
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(())
}
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(())
}
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(())
}