Skip to main content

Crate ps_compress

Crate ps_compress 

Source
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§

CompressionError
Errors returned by compress and compress_into.
DecompressionError
Errors returned by decompress, decompress_bounded, and decompress_into.

Functions§

compress
Compresses data and allocates an output buffer for the compressed bytes.
compress_into
Compresses data into an existing output buffer.
decompress
Decompresses data, allocating an output buffer sized from frame metadata.
decompress_bounded
Decompresses data, allocating an output buffer up to max_output_bytes.
decompress_into
Decompresses data into an existing output buffer.