#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

#104 in Compression

Download history 388/week @ 2024-07-21 222/week @ 2024-07-28 175/week @ 2024-08-04 263/week @ 2024-08-11 196/week @ 2024-08-18 111/week @ 2024-08-25 184/week @ 2024-09-01 455/week @ 2024-09-08 233/week @ 2024-09-15 163/week @ 2024-09-22 114/week @ 2024-09-29 245/week @ 2024-10-06 282/week @ 2024-10-13 432/week @ 2024-10-20 297/week @ 2024-10-27 94/week @ 2024-11-03

1,138 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–7.5MB
~65K SLoC