Crates.io | compu |
lib.rs | compu |
version | |
source | src |
created_at | 2019-05-21 17:19:51.582357 |
updated_at | 2024-12-01 08:11:28.664861 |
description | Rust Compression library with generic interface |
homepage | |
repository | https://github.com/DoumanAsh/compu |
max_upload_size | |
id | 135902 |
Cargo.toml error: | TOML parse error at line 24, column 1 | 24 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Rust Compression library with generic interface
All features are off by default.
This crate requires alloc
to be available with system allocator set.
brotli-c
- Enables brotli
interface using C library.brotli-rust
- Enables brotli
interface using pure Rust library.zlib-ng
- Enables zlib-ng
interface.zlib
- Enables zlib
interface.zlib-static
- Enables zlib
interface with static
feature.zstd
- Enables zstd
interface.bytes
- Enables bytes
supportMinimal example of using Decoder.
Use Interface
to create instance.
use compu::{Decoder, DecodeStatus, DecodeError};
fn example(decoder: &mut Decoder, input: &[u8]) -> Result<Vec<u8>, DecodeError> {
let mut output = Vec::with_capacity(1024);
loop {
let result = decoder.decode_vec(input, &mut output).status?;
match result {
DecodeStatus::NeedInput => panic!("Not enough input, incomplete data?"),
//If you need more output, please allocate spare capacity.
//API never allocates, only you allocate
DecodeStatus::NeedOutput => output.reserve(1024),
DecodeStatus::Finished => {
//Make sure to reset state, if you want to re-use decoder.
decoder.reset();
break Ok(output)
}
}
}
}
Minimal example of using Encoder.
Use Interface
to create instance.
use compu::{Encoder, EncodeStatus, EncodeOp};
fn example(encoder: &mut Encoder, input: &[u8]) -> Vec<u8> {
let mut output = Vec::with_capacity(1024);
loop {
let result = encoder.encode_vec(input, &mut output, EncodeOp::Finish).status;
match result {
//This status is returned by any other `EncodeOp` except `Finish
EncodeStatus::Continue => panic!("I wanted to finish but continue!?"),
//If you need more output, please allocate spare capacity.
//API never allocates, only you allocate
EncodeStatus::NeedOutput => output.reserve(1024),
//If you have enough space, `EncodeOp::Finish` will result in this operation
EncodeStatus::Finished => {
//Make sure to reset state, if you want to re-use it.
encoder.reset();
break output;
}
//Generally can indicate internal error likely due to OOM condition.
//Note that all wrappers ensure that Rust's global allocator is used,
//so take care if you use custom one
//Generally should not happen, so it is ok to just panic
//but be a good boy and return error properly if it happens, even if it is unlikely
EncodeStatus::Error => {
panic!("unlikely")
}
}
}
}