Skip to main content

compress_lib/
lib.rs

1//! # compress_lib
2//!
3//! DEFLATE (RFC 1951), zlib (RFC 1950), and gzip (RFC 1952) for Rust
4//! services, with the per-message rules of WebSocket permessage-deflate
5//! (RFC 7692).
6//!
7//! The engine is sans-IO: the caller pushes input and pulls output through
8//! buffers it owns. Memory is fixed when an engine is built and never grows
9//! with input, and every decoder enforces an absolute output cap while it
10//! decodes, so a decompression bomb costs at most the cap. There is no
11//! `unsafe` code and no third-party runtime dependency.
12//!
13//! ## Tier 1
14//!
15//! Add it with Cargo's rename, `compress = { package = "compress-lib", version
16//! = "0.2" }`, and code reads `compress::`. In 0.2 the checksums are ready:
17//!
18//! ```
19//! use compress_lib::checksum::{adler32, crc32};
20//!
21//! assert_eq!(crc32(b"123456789"), 0xCBF4_3926);
22//! assert_eq!(adler32(b"Wikipedia"), 0x11E6_0398);
23//! ```
24//!
25//! Decoders take [`Limits`] (64 MiB of output by default) and encoders a
26//! [`Level`] (0 to 9, zlib's meaning). Every failure is an [`Error`] with a
27//! matchable [`ErrorKind`] and a stable code for logs and metrics.
28//!
29//! ## Status
30//!
31//! `0.2.0`, the design lock: the complete planned API, each item with the
32//! version it arrives in, is `docs/API.md` in the
33//! [repository](https://github.com/jamesgober/compress-lib). The checksums,
34//! the error type, the limits, and the levels ship now; the raw DEFLATE
35//! inflater arrives in `0.3`, the deflater and the RFC 7692 helpers in `0.4`,
36//! zlib and gzip in `0.5`.
37
38#![doc(html_root_url = "https://docs.rs/compress-lib")]
39#![cfg_attr(docsrs, feature(doc_cfg))]
40#![cfg_attr(not(feature = "std"), no_std)]
41#![forbid(unsafe_code)]
42#![deny(missing_docs)]
43#![cfg_attr(
44    not(test),
45    deny(
46        clippy::unwrap_used,
47        clippy::expect_used,
48        clippy::panic,
49        clippy::todo,
50        clippy::unimplemented,
51        clippy::unreachable,
52        clippy::dbg_macro
53    )
54)]
55
56extern crate alloc;
57
58/// Crate version string, populated by Cargo at build time.
59pub const VERSION: &str = env!("CARGO_PKG_VERSION");
60
61pub mod checksum;
62
63mod error;
64mod level;
65mod limits;
66
67pub use error::{Error, ErrorKind};
68pub use level::Level;
69pub use limits::Limits;
70
71#[cfg(test)]
72mod tests {
73    use super::VERSION;
74
75    #[test]
76    fn test_version_matches_manifest() {
77        assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
78        let core = VERSION.split(['-', '+']).next().unwrap_or_default();
79        assert_eq!(core.split('.').count(), 3);
80        assert!(core.split('.').all(|part| part.parse::<u64>().is_ok()));
81    }
82}