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
- Gzip
- Zlib (Cannot suggest format from magic bytes and file extension)
- BZip2
- XZ
- Snappy (Cannot suggest format from file extension)
- Z-standard
- LZ4
- Brotli (Cannot suggest format from magic bytes)
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
Enums
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