### Example: autodetect_parallel_create_or_stdout usage Source: https://docs.rs/autocompress/latest/autocompress/fn.autodetect_parallel_create_or_stdout.html Example from the documentation showing how to create a writer for a .gz file. Uses `CompressionLevel::default()` and the `?` operator, so it must be called in a function returning a Result. ```rust let path = "target/doc-autodetect_parallel_create.gz"; let writer = autocompress::autodetect_parallel_create_or_stdout(Some(path), CompressionLevel::default())?; ``` -------------------------------- ### Example usage of autodetect_parallel_create Source: https://docs.rs/autocompress/latest/autocompress/fn.autodetect_parallel_create.html Example showing how to call autodetect_parallel_create with a path and default compression level. The path uses a .gz extension, and the function returns a Result that can be unwrapped with '?'. ```rust let path = "target/doc-autodetect_parallel_create.gz"; let writer = autocompress::autodetect_parallel_create(path, CompressionLevel::default())?; ``` -------------------------------- ### Example: Compress data with AsyncBgzipCompressWriter Source: https://docs.rs/autocompress/latest/autocompress/bgzip/type.AsyncBgzipCompressWriter.html Shows how to create an AsyncBgzipCompressWriter, write data, and shutdown. Uses async/await and requires the 'bgzip' and 'tokio' features. ```rust let file_writer = File::create("target/doc-bgzip-compress-async-writer.gz").await?; let mut bgzip_writer = AsyncBgzipCompressWriter::new(file_writer); bgzip_writer.write_all(&b"Hello, world"[..]).await?; bgzip_writer.shutdown().await?; ``` -------------------------------- ### Example: Create ProcessorWriter with ZstdCompress and write data Source: https://docs.rs/autocompress/latest/autocompress/io/struct.ProcessorWriter.html Shows how to create a ProcessorWriter with a custom processor (ZstdCompress) and write data. The example is not tested and uses File::create and write_all, which require error handling in practice. ```rust use autocompress::io::ProcessorWriter; use autocompress::zstd::ZstdCompress; let file_writer = File::create("target/doc-io-write-with-processor.zst")?; let zstd_compress = ZstdCompress::new(1)?; let mut zstd_writer = ProcessorWriter::::with_processor(zstd_compress, file_writer); zstd_writer.write_all(&b"Hello, world!"[..])?; ``` -------------------------------- ### Example: Compress data with AsyncBzip2CompressWriter Source: https://docs.rs/autocompress/latest/autocompress/bzip2/type.AsyncBzip2CompressWriter.html Shows how to create a file writer, wrap it with AsyncBzip2CompressWriter, write data, and shutdown. Uses async/await and requires the bzip2 and tokio features. ```rust let file_writer = File::create("target/doc-bzip2-compress-async-writer.gz").await?; let mut bzip2_writer = AsyncBzip2CompressWriter::new(file_writer); bzip2_writer.write_all(&b"Hello, world"[..]).await?; bzip2_writer.shutdown().await?; ``` -------------------------------- ### Example: Using autodetect_create with .zst file Source: https://docs.rs/autocompress/latest/autocompress/fn.autodetect_create.html Example usage of autodetect_create to create a file with a .zst extension and write data to it. Requires importing autodetect_create and CompressionLevel from the autocompress crate. ```rust use autocompress::{autodetect_create, CompressionLevel}; let mut writer = autodetect_create("target/doc-autodetect_create.zst", CompressionLevel::Default)?; writer.write_all(&b"Hello, world\n"[..])?; ``` -------------------------------- ### Example: Compress data asynchronously with AsyncGzipCompressWriter Source: https://docs.rs/autocompress/latest/autocompress/gzip/type.AsyncGzipCompressWriter.html Shows how to create a file, wrap it in AsyncGzipCompressWriter, write data, and shutdown. Uses async/await and requires the 'gzip' and 'tokio' features. ```rust let file_writer = File::create("target/doc-gzip-compress-async-writer.gz").await?; let mut gzip_writer = AsyncGzipCompressWriter::new(file_writer); gzip_writer.write_all(&b"Hello, world"[..]).await?; gzip_writer.shutdown().await?; ``` -------------------------------- ### Example: Using autodetect_buf_reader Source: https://docs.rs/autocompress/latest/autocompress/fn.autodetect_buf_reader.html Example usage of autodetect_buf_reader to read a compressed file, automatically detecting the decoder from the magic number. ```rust use autocompress::autodetect_buf_reader; let buf_reader = BufReader::new(File::open("testfiles/pg2701.txt.zst")?); let mut reader = autodetect_buf_reader(buf_reader)?; let mut buf = Vec::new(); reader.read_to_end(&mut buf)?; ``` -------------------------------- ### Example: Using autodetect_reader to decompress a file Source: https://docs.rs/autocompress/latest/autocompress/fn.autodetect_reader.html Example usage of autodetect_reader. It opens a file, creates a reader with autodetect_reader, and reads the decompressed content into a buffer. The example uses the ? operator, so it must be called within a function that returns a Result. ```rust use autocompress::autodetect_reader; let file_reader = File::open("testfiles/pg2701.txt.zst")?; let mut reader = autodetect_reader(file_reader)?; let mut buf = Vec::new(); reader.read_to_end(&mut buf)?; ``` -------------------------------- ### Example: Decompressing a GZIP File with AsyncGzipDecompressReader Source: https://docs.rs/autocompress/latest/autocompress/gzip/type.AsyncGzipDecompressReader.html Shows how to open a GZIP file, create an AsyncGzipDecompressReader, and read the decompressed data into a Vec. Requires the 'gzip' and 'tokio' features. ```rust let buf_reader = BufReader::new(File::open("testfiles/pg2701.txt.gz").await?); let mut gzip_reader = AsyncGzipDecompressReader::new(buf_reader); let mut buf = Vec::new(); gzip_reader.read_to_end(&mut buf).await?; ``` -------------------------------- ### AsyncXzCompressWriter Usage Example Source: https://docs.rs/autocompress/latest/autocompress/xz/type.AsyncXzCompressWriter.html Shows how to create an AsyncXzCompressWriter, write data, and shut it down. Requires the tokio and xz features. ```rust let file_writer = File::create("target/doc-xz-compress-async-writer.gz").await?; let mut xz_writer = AsyncXzCompressWriter::new(file_writer); xz_writer.write_all(&b"Hello, world"[..]).await?; xz_writer.shutdown().await?; ``` -------------------------------- ### Example: Using ProcessorWriter with ZstdCompress Source: https://docs.rs/autocompress/latest/autocompress/io/struct.ProcessorWriter.html Example usage of ProcessorWriter with ZstdCompress to write compressed data to a file. Requires a File::create call and error handling with ?. ```rust use autocompress::io::ProcessorWriter; use autocompress::zstd::ZstdCompress; let file_writer = File::create("target/doc-io-write.zst")?; let mut zstd_writer = ProcessorWriter::::new(file_writer); zstd_writer.write_all(&b"Hello, world!"[..])?; ``` -------------------------------- ### Example usage of AsyncZstdCompressWriter Source: https://docs.rs/autocompress/latest/autocompress/zstd/type.AsyncZstdCompressWriter.html Shows how to create an AsyncZstdCompressWriter, write data to it, and shut it down. Requires tokio and zstd features. ```rust let file_writer = File::create("target/doc-zstd-compress-async-writer.zst").await?; let mut zstd_writer = AsyncZstdCompressWriter::new(file_writer); zstd_writer.write_all(&b"Hello, world"[..]).await?; zstd_writer.shutdown().await?; ``` -------------------------------- ### Example: Using autodetect_open Source: https://docs.rs/autocompress/latest/autocompress/fn.autodetect_open.html Example usage of autodetect_open to open a compressed file and read its contents into a buffer. The decoder is selected based on magic number, not file extension. ```rust use autocompress::autodetect_open; let mut reader = autodetect_open("testfiles/pg2701.txt.zst")?; let mut buf = Vec::new(); reader.read_to_end(&mut buf)?; ``` -------------------------------- ### Example: reading decompressed data with ProcessorReader and ZstdDecompress Source: https://docs.rs/autocompress/latest/autocompress/io/struct.ProcessorReader.html Shows how to create a ProcessorReader with a ZstdDecompress processor and read decompressed data into a Vec. The example is not tested and uses ? for error handling. ```rust use autocompress::io::ProcessorReader; use autocompress::zstd::ZstdDecompress; let buf_reader = BufReader::new(File::open("testfiles/pg2701.txt.zst")?); let mut zstd_reader = ProcessorReader::::new(buf_reader); let mut buf = Vec::new(); zstd_reader.read_to_end(&mut buf)?; ``` -------------------------------- ### Example: Decompressing a BZip2 File with AsyncBzip2DecompressReader Source: https://docs.rs/autocompress/latest/autocompress/bzip2/type.AsyncBzip2DecompressReader.html Shows how to open a BZip2 file, create an AsyncBzip2DecompressReader, and read decompressed data into a vector. Uses async/await and requires the 'tokio' feature. ```rust let buf_reader = BufReader::new(File::open("testfiles/pg2701.txt.bz2").await?); let mut bzip2_reader = AsyncBzip2DecompressReader::new(buf_reader); let mut buf = Vec::new(); bzip2_reader.read_to_end(&mut buf).await?; ``` -------------------------------- ### Example: Compress data with GzipCompressWriter Source: https://docs.rs/autocompress/latest/autocompress/gzip/type.GzipCompressWriter.html Creates a file and writes compressed data using GzipCompressWriter. Requires the gzip feature and imports File and Write. ```rust use autocompress::gzip::GzipCompressWriter; let file_writer = File::create("target/doc-gzip-compress-writer.gz")?; let mut gzip_writer = GzipCompressWriter::new(file_writer); gzip_writer.write_all(&b"Hello, world"[..])?; ``` -------------------------------- ### Example usage of GzipDecompressReader Source: https://docs.rs/autocompress/latest/autocompress/gzip/type.GzipDecompressReader.html Shows how to create a GzipDecompressReader from a BufReader over a GZIP file and read decompressed data into a Vec. Requires the 'gzip' feature. ```rust use autocompress::gzip::GzipDecompressReader; let buf_reader = BufReader::new(File::open("testfiles/pg2701.txt.gz")?); let mut gzip_reader = GzipDecompressReader::new(buf_reader); let mut buf = Vec::new(); gzip_reader.read_to_end(&mut buf)?; ``` -------------------------------- ### Example: Decompressing an Xz File with AsyncXzDecompressReader Source: https://docs.rs/autocompress/latest/autocompress/xz/type.AsyncXzDecompressReader.html Shows how to create an AsyncXzDecompressReader from a BufReader over a file, read decompressed data into a Vec, and await the read_to_end operation. Requires the tokio and xz features. ```rust let buf_reader = BufReader::new(File::open("testfiles/pg2701.txt.xz").await?); let mut xz_reader = AsyncXzDecompressReader::new(buf_reader); let mut buf = Vec::new(); xz_reader.read_to_end(&mut buf).await?; ``` -------------------------------- ### Example: Using autodetect_open_or_stdin Source: https://docs.rs/autocompress/latest/autocompress/fn.autodetect_open_or_stdin.html Example usage of autodetect_open_or_stdin with a file path. It reads the decompressed content into a Vec. The function selects the decoder based on magic number, not file extension. ```rust use autocompress::autodetect_open_or_stdin; let mut reader = autodetect_open_or_stdin(Some("testfiles/pg2701.txt.zst"))?; let mut buf = Vec::new(); reader.read_to_end(&mut buf)?; ``` -------------------------------- ### Example: Asynchronously decompress a file with AsyncProcessorReader and ZstdDecompress Source: https://docs.rs/autocompress/latest/autocompress/io/struct.AsyncProcessorReader.html Shows how to create an AsyncProcessorReader with a ZstdDecompress processor and read the decompressed data into a Vec. Requires tokio and the autocompress tokio feature. ```rust use autocompress::io::AsyncProcessorReader; use autocompress::zstd::ZstdDecompress; let buf_reader = BufReader::new(File::open("testfiles/pg2701.txt.zst").await?); let mut zstd_reader = AsyncProcessorReader::::new(buf_reader); let mut buf = Vec::new(); zstd_reader.read_to_end(&mut buf).await?; ``` -------------------------------- ### AsyncProcessorWriter usage example with ZstdCompress Source: https://docs.rs/autocompress/latest/autocompress/io/struct.AsyncProcessorWriter.html Example showing how to create an AsyncProcessorWriter with ZstdCompress, write data asynchronously, and shut down. Requires the tokio feature and imports from autocompress::io and autocompress::zstd. ```rust use autocompress::io::AsyncProcessorWriter; use autocompress::zstd::ZstdCompress; let file_writer = File::create("target/doc-io-async-write.zst").await?; let mut zstd_writer = AsyncProcessorWriter::::new(file_writer); zstd_writer.write_all(&b"Hello, world!"[..]).await?; zstd_writer.shutdown().await?; ``` -------------------------------- ### Example: Decompressing a Zstd File with AsyncZstdDecompressReader Source: https://docs.rs/autocompress/latest/autocompress/zstd/type.AsyncZstdDecompressReader.html Shows how to create an AsyncZstdDecompressReader from a buffered reader and read decompressed data into a vector. Uses async/await and requires the tokio and zstd features. ```rust let buf_reader = BufReader::new(File::open("testfiles/pg2701.txt.zst").await?); let mut zstd_reader = AsyncZstdDecompressReader::new(buf_reader); let mut buf = Vec::new(); zstd_reader.read_to_end(&mut buf).await?; ``` -------------------------------- ### Example: Using RayonWriter with ZstdCompressWriter Source: https://docs.rs/autocompress/latest/autocompress/io/struct.RayonWriter.html Shows how to create a RayonWriter wrapping a ZstdCompressWriter and write data to a file. The write operation is offloaded to another thread, but compression is not parallelized. ```rust use autocompress::io::RayonWriter; use autocompress::zstd::ZstdCompressWriter; let file_writer = File::create("target/rayon-doc-write.zst")?; let zstd_writer = ZstdCompressWriter::new(file_writer); let mut rayon_writer = RayonWriter::new(zstd_writer); rayon_writer.write_all(&b"Hello, world\n"[..])?; ``` -------------------------------- ### Create AsyncProcessorWriter with ZstdCompress Source: https://docs.rs/autocompress/latest/autocompress/io/struct.AsyncProcessorWriter.html Shows how to create an AsyncProcessorWriter with a ZstdCompress processor and write data. Requires a File writer and uses async/await. The example writes "Hello, world!" and then shuts down the writer. ```rust use autocompress::io::AsyncProcessorWriter; use autocompress::zstd::ZstdCompress; let file_writer = File::create("target/doc-io-async-write-with-processor.zst").await?; let zstd_compress = ZstdCompress::new(1)?; let mut zstd_writer = AsyncProcessorWriter::with_processor(zstd_compress, file_writer); zstd_writer.write_all(&b"Hello, world!"[..]).await?; zstd_writer.shutdown().await?; ``` -------------------------------- ### Parallel compression using autodetect_parallel_create Source: https://docs.rs/autocompress/latest/autocompress/index.html Creates a compressed file with parallel compression enabled, using autodetect_parallel_create. Writes the same data as the non-parallel example. ```rust use autocompress::{autodetect_parallel_create, CompressionLevel}; let mut writer = autodetect_parallel_create("target/doc-index2.xz", CompressionLevel::Default)?; writer.write_all(&b"Hello, world\n"[..])?; ``` -------------------------------- ### Create ParallelCompressWriter with new Source: https://docs.rs/autocompress/latest/autocompress/io/struct.ParallelCompressWriter.html Constructs a ParallelCompressWriter using the new method. The writer is a File created at 'target/rayon-parallel-writer.txt.gz', and the processor generator returns a GzipCompress::default(). The example writes 'Hello, world\n' to the parallel writer. ```rust let writer = File::create("target/rayon-parallel-writer.txt.gz")?; let mut parallel_writer = ParallelCompressWriter::new(writer, || GzipCompress::default()); parallel_writer.write_all(&b"Hello, world\n"[..])?; ``` -------------------------------- ### RayonReader usage example Source: https://docs.rs/autocompress/latest/autocompress/io/struct.RayonReader.html Example of using RayonReader with a ZstdDecompressReader to read a compressed file. Requires the 'rayon' feature. ```rust use autocompress::io::RayonReader; use autocompress::zstd::ZstdDecompressReader; let buf_reader = BufReader::new(File::open("testfiles/pg2701.txt.zst")?); let zstd_reader = ZstdDecompressReader::new(buf_reader); let mut rayon_reader = RayonReader::new(zstd_reader); let mut buf = Vec::new(); rayon_reader.read_to_end(&mut buf)?; ``` -------------------------------- ### Using ProcessorReader::with_processor with ZstdDecompress Source: https://docs.rs/autocompress/latest/autocompress/io/struct.ProcessorReader.html Example from the docs for with_processor. It creates a ProcessorReader with a ZstdDecompress processor and a BufReader, then reads the decompressed content into a Vec. Note: this example is not tested. ```rust use autocompress::io::ProcessorReader; use autocompress::zstd::ZstdDecompress; let buf_reader = BufReader::new(File::open("testfiles/pg2701.txt.zst")?); let zstd_decompress = ZstdDecompress::new()?; let mut zstd_reader = ProcessorReader::with_processor(zstd_decompress, buf_reader); let mut buf = Vec::new(); zstd_reader.read_to_end(&mut buf)?; ``` -------------------------------- ### Pointable::Init Source: https://docs.rs/autocompress/latest/autocompress/io/struct.SystemThreadBuilder.html The type for initializers. ```APIDOC ## Pointable::Init ### Description The type for initializers. ### Associated Type `type Init = T` ``` -------------------------------- ### XzCompress::new Source: https://docs.rs/autocompress/latest/autocompress/xz/struct.XzCompress.html Creates a new XzCompress instance with the specified compression preset. Returns a Result indicating success or failure. ```APIDOC ## XzCompress::new ### Description Creates a new XzCompress instance with the specified compression preset. ### Method `pub fn new(preset: u32) -> Result` ### Parameters - **preset** (u32) - Required - Compression preset level. ### Returns - `Result` - A Result containing the new XzCompress instance on success, or an error on failure. ``` -------------------------------- ### Pointable::init Source: https://docs.rs/autocompress/latest/autocompress/io/struct.SystemThreadBuilder.html Initializes a with the given initializer. ```APIDOC ## Pointable::init ### Description Initializes a with the given initializer. ### Method `unsafe fn init(init: ::Init) -> usize` ### Parameters - **init** (`::Init`) - The initializer value. ### Returns - `usize` - The initialized pointer. ``` -------------------------------- ### take Source: https://docs.rs/autocompress/latest/autocompress/io/struct.RayonReader.html Creates an adapter which will limit the number of bytes read from this stream. ```APIDOC ## take ### Description Creates an adapter which will limit the number of bytes read from this stream. ### Method take ### Signature fn take(self, limit: u64) -> Take where Self: Sized ### Parameters - **limit** (u64) - Required - The maximum number of bytes to read. ### Returns Take - An adapter that limits the number of bytes read. ``` -------------------------------- ### impl Processor for GzipCompress Source: https://docs.rs/autocompress/latest/autocompress/gzip/struct.GzipCompress.html The GzipCompress struct implements the Processor trait, providing methods to process input data, reset state, and get total input/output byte counts. ```APIDOC ## impl Processor for GzipCompress ### Description Provides gzip compression processing capabilities through the Processor trait. ### Methods #### process - **Signature**: `fn process(&mut self, input: &[u8], output: &mut [u8], flush: Flush) -> Result` - **Description**: Processes some input data and generates output data. - **Parameters**: - `input` (`&[u8]`) - Input data to process. - `output` (`&mut [u8]`) - Buffer to write output data. - `flush` (`Flush`) - Flush mode for the compression. - **Returns**: `Result` - The status of the operation. #### reset - **Signature**: `fn reset(&mut self)` - **Description**: Resets the processor state. #### total_in - **Signature**: `fn total_in(&self) -> u64` - **Description**: Returns the total number of bytes processed. #### total_out - **Signature**: `fn total_out(&self) -> u64` - **Description**: Returns the total number of bytes generated. ``` -------------------------------- ### Create ParallelCompressWriter with with_buffer_size Source: https://docs.rs/autocompress/latest/autocompress/io/struct.ParallelCompressWriter.html Constructs a ParallelCompressWriter with a specified buffer size and count. The example uses a buffer size of 1024 * 1024 and a buffer count of 50. The writer is a File created at 'target/rayon-parallel-writer-with-buffer.txt.gz'. ```rust let writer = File::create("target/rayon-parallel-writer-with-buffer.txt.gz")?; let mut parallel_writer = ParallelCompressWriter::with_buffer_size(writer, || GzipCompress::default(), 1024 * 1024, 50); parallel_writer.write_all(&b"Hello, world\n"[..])?; ``` -------------------------------- ### take Source: https://docs.rs/autocompress/latest/autocompress/io/struct.AsyncProcessorReader.html Creates an adaptor which reads at most `limit` bytes from the source. This method is part of the AsyncReadExt trait. ```APIDOC ## take ### Description Creates an adaptor which reads at most `limit` bytes from it. ### Method take ### Signature fn take(self, limit: u64) -> Take where Self: Sized ### Parameters - **limit** (u64) - Required - The maximum number of bytes to read. ### Returns - **Take** - An adaptor that limits the number of bytes read. ### Source [Source](https://docs.rs/tokio/1.54.0/x86_64-unknown-linux-gnu/tokio/io/util/async_read_ext/trait.AsyncReadExt.html#method.take) ``` -------------------------------- ### autodetect_async_create_or_stdout Source: https://docs.rs/autocompress/latest/autocompress/ Creates a file or opens standard output, and automatically selects a suitable encoder from file extension, async version. ```APIDOC ## autodetect_async_create_or_stdout ### Description Create a file or open standard input, and automatically select a suitable encoder from file extension, async version. ### Function `autocompress::autodetect_async_create_or_stdout` ### Feature `tokio_fs` ``` -------------------------------- ### Read from a file using autodetect_open Source: https://docs.rs/autocompress/latest/autocompress/ Opens a compressed file with automatic format detection and reads its contents into a Vec. The example uses the xz format but works with any supported format. Requires the corresponding feature flag for the format. ```rust use autocompress::autodetect_open; let mut reader = autodetect_open("testfiles/pg2701.txt.xz")?; let mut buf = Vec::new(); reader.read_to_end(&mut buf)?; ``` -------------------------------- ### ProcessorWriter::new Source: https://docs.rs/autocompress/latest/autocompress/io/struct.ProcessorWriter.html Creates a new ProcessorWriter with default buffer size and default processor configuration. ```APIDOC ## ProcessorWriter::new ### Description Creates a new ProcessorWriter with default buffer size and default configuration of the processor. ### Method `pub fn new(writer: W) -> Self` ### Parameters - `writer` (W) - Required - The underlying writer to write processed data to. ### Returns - `Self` - A new ProcessorWriter instance. ### Example See the example in the `ProcessorWriter` documentation for usage. ``` -------------------------------- ### PlainProcessor::new Source: https://docs.rs/autocompress/latest/autocompress/struct.PlainProcessor.html Creates a new PlainProcessor instance. This processor does not compress or decompress data, transferring data as is. ```APIDOC ## PlainProcessor::new ### Description Creates a new PlainProcessor instance. This processor does not compress or decompress data, transferring data as is. ### Method `pub fn new() -> Self` ### Parameters None. ### Returns - `Self` - A new PlainProcessor instance. ``` -------------------------------- ### AsyncProcessorWriter::new Source: https://docs.rs/autocompress/latest/autocompress/io/struct.AsyncProcessorWriter.html Creates a new AsyncProcessorWriter with default processor and buffer size. ```APIDOC ## AsyncProcessorWriter::new ### Description Creates a new AsyncProcessorWriter with default processor and buffer size. ### Method new ### Signature pub fn new(writer: W) -> Self ### Parameters - **writer** (W) - Required - The underlying async writer. ### Returns - **Self** - A new AsyncProcessorWriter instance. ``` -------------------------------- ### Write to a file using autodetect_create Source: https://docs.rs/autocompress/latest/autocompress/index.html Creates a compressed file with automatic format detection based on the file extension and writes data to it. Uses CompressionLevel::Default and writes the bytes 'Hello, world\n'. ```rust use autocompress::{autodetect_create, CompressionLevel}; let mut writer = autodetect_create("target/doc-index.xz", CompressionLevel::Default)?; writer.write_all(&b"Hello, world\n"[..])?; ```