Skip to main content

Module resource_compression

Module resource_compression 

Source
Expand description

RNS 1.4.2 Resource bz2, the half the pure engine leaves to its host. prns-core carries a resource as an opaque stream and flags it compressed or not; the codec is the host’s, because bz2 is unavailable on the embedded targets the core also serves. The tokio host has no such limit, so it compresses every outgoing resource and inflates every compressed one, and a std node speaks the reference’s wire compression byte-for-byte.

Pure-Rust bz2 (bzip2’s default libbz2-rs-sys backend): no C toolchain, and nothing for the crate’s forbid(unsafe_code) to trip on.

Enums§

DecompressError

Constants§

SAMPLE_GATE_LEN
Sampling pays ~5 ms to sidestep an ~80 ms attempt at 1 MiB; below this the full attempt is cheap enough to just run, and every input stays on the reference’s exact path.

Functions§

compress_if_smaller
RNS 1.4.2 Resource.__init__: bz2.compress at level 9 (its default), kept only when it comes out strictly smaller than the input. None is the reference’s else-branch: send the payload as-is with the c flag clear. For already-dense bytes bz2 only adds overhead, so the reference, and we, decline it.
compress_resource_candidate
decompress_bounded
RNS 1.4.2’s bounded bz2 inflate, BZ2Decompressor(...).decompress(data, max_length=…) with the eof check: inflate to at most max_len, refusing a stream that would run past it. Both callers cap max_len at host policy (a resource’s advertised length, already gated by the link’s ResourceStrategy; a stream chunk’s channel MDU), so a bz2 bomb can force neither an unbounded allocation nor an unbounded inflate. A resource caller passes its exact advertised length and re-checks it on assembly, so a stream that inflates short is caught there.