Crates.io | autocompress |
lib.rs | autocompress |
version | 0.6.0 |
source | src |
created_at | 2020-04-01 15:36:35.803535 |
updated_at | 2023-12-24 12:36:15.509944 |
description | Automatically select suitable decoder from magic bytes or encoder from file extension. |
homepage | https://github.com/informationsea/autocompress-rs |
repository | https://github.com/informationsea/autocompress-rs |
max_upload_size | |
id | 225236 |
size | 256,767 |
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
: 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
: Enable autodetect_async_open
functionuse 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(())
}