autocompress

Crates.ioautocompress
lib.rsautocompress
version0.6.0
sourcesrc
created_at2020-04-01 15:36:35.803535
updated_at2023-12-24 12:36:15.509944
descriptionAutomatically select suitable decoder from magic bytes or encoder from file extension.
homepagehttps://github.com/informationsea/autocompress-rs
repositoryhttps://github.com/informationsea/autocompress-rs
max_upload_size
id225236
size256,767
Yasunobu Okamura (informationsea)

documentation

README

autocompress-rs

Build GitHub GitHub top language Crates.io Docs.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

Feature flags

  • gzip : Gzip format support
  • bgzip : bgzip format support
  • bzip2 : Bzip2 format support
  • xz : XZ format support
  • zstd : Zstd format support
  • rayon : Off-load compression and decompression process to another thread using rayon
  • tokio : Async reader and writer support with tokio
  • tokio_fs: Enable autodetect_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(())
}
Commit count: 60

cargo fmt