compu/lib.rs
1//!Rust Compression library with generic interface
2//!
3//!## API
4//!
5//!API is mostly thin layer that provides uniform behavior for all algorithms the best it can.
6//!
7//!Please read documentation to see how to use:
8//!
9//!- [Decoder](decoder/struct.Decoder.html)
10//!- [Encoder](encoder/struct.Encoder.html)
11//!
12//!## Features
13//!
14//!All features are off by default.
15//!This crate requires `alloc` to be available with system allocator set.
16//!
17//!- `brotli-c` - Enables `brotli` interface using C library.
18//!- `brotli-rust` - Enables `brotli` interface using pure Rust library.
19//!- `zlib` - Enables `zlib` interface.
20//!- `zlib-static` - Enables `zlib` interface with `static` feature.
21//!- `zlib-ng` - Enables `zlib-ng` interface.
22//!- `zlib-rust` - Enables `zlib-rs` interface.
23//!- `zstd` - Enables `zstd` interface.
24//!- `bytes` - Enables `bytes` support
25//!
26//!## Usage
27//!
28//!### Decode
29//!
30//!Minimal example of using Decoder.
31//!Use [Interface](decoder/struct.Interface.html) to create instance.
32//!
33//!If you unsure about compression used, you can try [detect](decoder/enum.Detection.html#method.detect) it
34//!
35//!```rust,no_run
36//!use compu::{Decoder, DecodeStatus, DecodeError};
37//!
38//!fn example(decoder: &mut Decoder, input: &[u8]) -> Result<Vec<u8>, DecodeError> {
39//! let mut output = Vec::with_capacity(1024);
40//! loop {
41//! let result = decoder.decode_vec(input, &mut output).status?;
42//! match result {
43//! DecodeStatus::NeedInput => panic!("Not enough input, incomplete data?"),
44//! //If you need more output, please allocate spare capacity.
45//! //API never allocates, only you allocate
46//! DecodeStatus::NeedOutput => output.reserve(1024),
47//! DecodeStatus::Finished => {
48//! //Make sure to reset state, if you want to re-use decoder.
49//! decoder.reset();
50//! break Ok(output)
51//! }
52//! }
53//! }
54//!}
55//!```
56//!
57//!### Encode
58//!
59//!Minimal example of using Encoder.
60//!Use [Interface](encoder/struct.Interface.html) to create instance.
61//!
62//!```rust,no_run
63//!use compu::{Encoder, EncodeStatus, EncodeOp};
64//!
65//!fn example(encoder: &mut Encoder, input: &[u8]) -> Vec<u8> {
66//! let mut output = Vec::with_capacity(1024);
67//! loop {
68//! let result = encoder.encode_vec(input, &mut output, EncodeOp::Finish).status;
69//! match result {
70//! //This status is returned by any other `EncodeOp` except `Finish
71//! EncodeStatus::Continue => panic!("I wanted to finish but continue!?"),
72//! //If you need more output, please allocate spare capacity.
73//! //API never allocates, only you allocate
74//! EncodeStatus::NeedOutput => output.reserve(1024),
75//! //If you have enough space, `EncodeOp::Finish` will result in this operation
76//! EncodeStatus::Finished => {
77//! //Make sure to reset state, if you want to re-use it.
78//! encoder.reset();
79//! break output;
80//! }
81//! //Generally can indicate internal error likely due to OOM condition.
82//! //Note that all wrappers ensure that Rust's global allocator is used,
83//! //so take care if you use custom one
84//! //Generally should not happen, so it is ok to just panic
85//! //but be a good boy and return error properly if it happens, even if it is unlikely
86//! EncodeStatus::Error => {
87//! panic!("unlikely")
88//! }
89//! }
90//! }
91//!}
92//!```
93
94#![no_std]
95#![warn(missing_docs)]
96#![allow(clippy::style, clippy::derivable_impls)]
97
98pub mod decoder;
99#[cfg(any(
100 feature = "zlib",
101 feature = "zlib-static",
102 feature = "zlib-ng",
103 feature = "brotli-c",
104 feature = "zstd"
105))]
106pub(crate) mod utils;
107pub use decoder::{Decode, DecodeError, DecodeStatus, Decoder, Detection};
108pub mod encoder;
109pub use encoder::{Encode, EncodeOp, EncodeStatus, Encoder};
110mod buffer;
111pub mod mem;
112pub use buffer::Buffer;