Crate autocompress[][src]

Expand description

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

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};

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")?;

Modules

Run compression, decompression and other IO tasks in separated threads. Please read IoThread to learn more.

Structs

structure of decoding reader

structure of encoding writer

Enums

List of compression levels

List of supported file formats

Functions

Create new writer from file path. File format is suggested from file extension.

Create new writer from a file path. If a file path is None, standard output is used. File format is suggested from file extension.

Open new reader from file path. File format is suggested from magic bytes and file extension.

Open new reader from file path. If path is None, standard input is used. File format is suggested from magic bytes and file extension.

Suggest file format from magic bytes. This function does not consume data.

Suggest file format from a path extension