Expand description
§ps-compress
Deterministic Zstandard compression for small binary payloads.
This crate exposes a small API around zstd with a fixed compression policy (zstd level 7), suitable for use-cases where the same input must always compress to the same output bytes.
§API
compress(data: &[u8]) -> Result<Buffer, CompressionError>compress_into(data: &[u8], out_data: &mut [u8]) -> Result<usize, CompressionError>decompress(data: &[u8]) -> Result<Buffer, DecompressionError>decompress_bounded(data: &[u8], max_output_bytes: usize) -> Result<Buffer, DecompressionError>decompress_into(data: &[u8], out_data: &mut [u8]) -> Result<usize, DecompressionError>
§Example
use ps_compress::{compress, decompress};
let input = b"example payload";
let compressed = compress(input)?;
let decompressed = decompress(&compressed)?;
assert_eq!(decompressed.as_slice(), input);§Determinism Notes
- Compression parameters are fixed by this crate.
- For strict cross-environment determinism, keep the crate dependency pinned so all environments use the same zstd implementation version.
Enums§
- Compression
Error - Errors returned by
compressandcompress_into. - Decompression
Error - Errors returned by
decompress,decompress_bounded, anddecompress_into.
Functions§
- compress
- Compresses
dataand allocates an output buffer for the compressed bytes. - compress_
into - Compresses
datainto an existing output buffer. - decompress
- Decompresses
data, allocating an output buffer sized from frame metadata. - decompress_
bounded - Decompresses
data, allocating an output buffer up tomax_output_bytes. - decompress_
into - Decompresses
datainto an existing output buffer.