#gzip #zstd #bzip2 #compress #decompress

autocompress

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

4 releases

0.2.2 Jul 18, 2021
0.2.1 Jul 16, 2021
0.2.0 Jul 13, 2021
0.1.0 Apr 1, 2020

#52 in Compression

27 downloads per month

Apache-2.0

82KB
1.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

  • default, full: Enable all features.
  • gzip: Enable gzip
  • snap: Enable snappy
  • zstd: Enable Z-standard
  • bzip2: Enable bzip2
  • lz4: Enable LZ4
  • xz: Enable XZ
  • brotli: Enable Brotli
  • thread: Enable threaded I/O

Example

use autocompress::open;
use std::io::{self, Read};

fn main() -> io::Result<()> {
  let mut buffer = Vec::new();
  open("testfiles/plain.txt.xz")?.read_to_end(&mut buffer)?;
  assert_eq!(buffer, b"ABCDEFG\r\n1234567");
  Ok(())
}

I/O thread example

use autocompress::{iothread::IoThread, open, create, CompressionLevel};
use std::io::{prelude::*, self};
fn main() -> io::Result<()> {
 let thread_pool = IoThread::new(2);
 let mut threaded_reader = thread_pool.open("testfiles/plain.txt.xz")?;
 let mut threaded_writer = thread_pool.create("target/plain.txt.xz", CompressionLevel::Default)?;
 let mut buffer = Vec::new();
 threaded_reader.read_to_end(&mut buffer)?;
 assert_eq!(buffer, b"ABCDEFG\r\n1234567");
 threaded_writer.write_all(b"ABCDEFG\r\n1234567")?;
 Ok(())
}

Dependencies

~0–2.7MB
~59K SLoC