Crates.io | deko |
lib.rs | deko |
version | 0.1.0 |
source | src |
created_at | 2024-11-11 21:47:34.195084 |
updated_at | 2024-11-11 21:47:34.195084 |
description | A decoder that automatically detects compression format (gzip, bzip2, xz, zstd) via external crates. Includes an encoder for the same formats as well. |
homepage | https://github.com/igankevich/deko |
repository | https://github.com/igankevich/deko |
max_upload_size | |
id | 1444244 |
size | 57,160 |
A decoder that automatically detects compression format (gzip, bzip2, xz, zstd) via external crates. Includes an encoder for the same formats as well.
deko
is a library that offers AnyDecoder
and AnyEcnoder
structs
that can decompress/compress the data from/to a variaty formats via the corresponding crates.
The format is automatically detected via magic bytes — signatures at the start of the file.
Currently the following formats are supported:
Unused formats can be disabled via crate's features. By default all formats are enabled.
use deko::Format;
use deko::bufread::AnyDecoder;
use deko::write::{AnyEncoder, Compression};
use std::io::Read;
use std::io::Write;
let mut writer = AnyEncoder::new(Vec::new(), Format::Gz, Compression::Best).unwrap();
writer.write_all(b"Hello world").unwrap();
let compressed_data = writer.finish().unwrap();
let mut reader = AnyDecoder::new(&compressed_data[..]);
let mut string = String::new();
reader.read_to_string(&mut string);
assert_eq!("Hello world", string);