#file-extension #file-format #decompression #gzip #zstd #bzip2

autocompress

Automatically select suitable decoder from magic bytes or encoder from file extension

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

#101 in Compression

Download history 148/week @ 2024-08-08 269/week @ 2024-08-15 149/week @ 2024-08-22 132/week @ 2024-08-29 238/week @ 2024-09-05 530/week @ 2024-09-12 145/week @ 2024-09-19 112/week @ 2024-09-26 271/week @ 2024-10-03 258/week @ 2024-10-10 448/week @ 2024-10-17 172/week @ 2024-10-24 226/week @ 2024-10-31 396/week @ 2024-11-07 352/week @ 2024-11-14 278/week @ 2024-11-21

1,258 downloads per month
Used in proxy-rs

Apache-2.0

210KB
4.5K SLoC

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(())
}

Dependencies

~0.3–8MB
~64K SLoC