mod compression¶
- module compression¶
Functions
- fn detect_compression(bytes: &[u8]) -> Compression¶
Detect compression format from the first bytes of a file.
1f 8b= gzip28 b5 2f fd= zstdOtherwise = uncompressed
- fn detect_compression_from_extension(path: &Path) -> Compression¶
Detect compression format from a file extension.
Returns
Compression::Gzipfor.gz,Compression::Zstdfor.zst,Compression::Noneotherwise.
- fn gzip_writer(path: &Path) -> io::Result<flate2::write::GzEncoder<std::fs::File>>¶
Creates a gzip-compressed writer wrapping a file at the given path.
- fn read_file_contents(path: &Path) -> Result<FileContents, Box<dyn std::error::Error>>¶
Reads file contents, decompressing if needed.
Detection strategy: 1. Read first 2 bytes to check magic bytes. 2. If gzip: decompress entire file to a String. 3. If uncompressed and < 64 KiB:
read_to_string. 4. If uncompressed and >= 64 KiB: memory-mapped I/O.
- fn zstd_writer(path: &Path) -> io::Result<zstd::stream::write::AutoFinishEncoder<'static, std::fs::File>>¶
Creates a zstd-compressed writer wrapping a file at the given path.
Returns a finished writer ready for streaming line writes; the caller is responsible for dropping the writer to flush the final frame. Available only when the
zstdCargo feature is enabled.
Enums
- enum Compression¶
Detected compression format based on magic bytes.
Zstdis only constructed when thezstdCargo feature is enabled. Builds without the feature treat.zstfiles as opaque bytes and return an error fromread_file_contentsindicating the feature is required.- None¶
- Gzip¶
- Zstd¶
zstd frame, magic
28 B5 2F FD. Build with--features zstd.