Skip to main content

Crate bun_zstd

Crate bun_zstd 

Source
Expand description

bun_zstd - pure Rust zstd via zstd_pure_rs (replaces vendor/zstd C library). All compress/decompress delegates to zstd_pure_rs::prelude.

Re-exports§

pub use zstd_pure_rs::prelude::ZSTD_EndDirective::ZSTD_e_continue;
pub use zstd_pure_rs::prelude::ZSTD_ResetDirective::ZSTD_reset_session_and_parameters;

Modules§

error_codes
Error code constants — kept as c_uint values for NativeZstd compatibility.

Structs§

InBuffer
Rust-native buffer types replacing the C FFI ZSTD_inBuffer/ZSTD_outBuffer. NativeZstd’s Context uses these instead of raw pointers.
OutBuffer
ZSTD_CCtx
Port of ZSTD_CCtx. Holds a reusable match state, seqStore, and entropy tables so successive ZSTD_compressCCtx calls amortize allocation. Also backs the simple streaming API — initCStream captures the level, compressStream buffers input, endStream compresses the buffered input and drains the result.
ZstdReaderArrayList

Enums§

Result
State
ZSTD_DResetDirective
Port of ZSTD_ResetDirective (decoder-side alias).
ZSTD_EndDirective
Port of ZSTD_EndDirective. Tells ZSTD_compressStream2 whether the current call should flush / end the frame / just continue buffering.
ZSTD_ErrorCode
Sum of all ZSTD error codes. Values are fixed by upstream and must not drift; they are serialized indirectly through (size_t)-code return values from the C-compatible API.
ZSTD_ResetDirective
Port of ZSTD_ResetDirective (zstd.h:589). Upstream fixes the discriminants at 1/2/3 — not the Rust default 0/1/2. FFI callers passing the numeric values directly rely on this.
ZSTD_cParameter
Port of ZSTD_cParameter — the parameter id enum for the parametric ZSTD_CCtx_setParameter / ZSTD_CCtx_getParameter API. Only the subset that our compressor actually honors is exposed; unsupported ids return ParameterUnsupported.
ZSTD_dParameter
Port of ZSTD_dParameter — parametric decoder configuration. Only the subset we honor is exposed; callers setting unsupported ids get ParameterUnsupported.
ZstdError

Constants§

ZSTD_CONTENTSIZE_ERROR
ZSTD_CONTENTSIZE_UNKNOWN

Functions§

ZSTD_CCtx_reset
Port of ZSTD_CCtx_reset. Matches upstream’s three modes:
ZSTD_CCtx_setParameter
Port of ZSTD_CCtx_setParameter. Stashes the value on the CCtx for subsequent calls. For compressionLevel, behavior matches ZSTD_initCStream(level). For the frame flags, the next compression call honors them.
ZSTD_CCtx_setPledgedSrcSize
Port of ZSTD_CCtx_setPledgedSrcSize. Declares the exact number of bytes the caller intends to feed through compressStream before endStream. When set, the emitted frame header includes the content-size field (enabling some decoder optimizations) and ZSTD_getCParams uses the hint to pick tighter cParams.
ZSTD_DCtx_reset
Port of ZSTD_DCtx_reset. Matches upstream’s three modes: clear per-frame streaming state on session_only, restore default parameters + drop the configured dict on parameters, do both on session_and_parameters.
ZSTD_DCtx_setParameter
Port of ZSTD_DCtx_setParameter. For windowLogMax we record the bound on the DCtx for potential upper-bound checks during frame-header parsing. v0.1 just stashes the value; the enforcement path lands alongside the ZSTD_windowLog_max limit check.
ZSTD_compressStream2
Port of ZSTD_compressStream2. Unified streaming compression entry point that dispatches based on end_op:
ZSTD_createCCtx
Port of ZSTD_createCCtx. Returns an empty context — all heap allocations happen lazily on the first ZSTD_compressCCtx call.
ZSTD_createDCtx
Port of ZSTD_createDCtx. Rust port returns an owned ZSTD_DCtx with default seq-tables pre-built.
ZSTD_decompressStream
Port of ZSTD_decompressStream. Buffers input[input_pos..] into the DCtx, detects when a complete frame has been received via ZSTD_findFrameCompressedSize, decodes it into an internal output buffer, and drains the result into output[output_pos..].
ZSTD_defaultCLevel
Port of ZSTD_defaultCLevel. Upstream default is 3.
ZSTD_freeCCtx
Port of ZSTD_freeCCtx. Drop the context; Rust’s Box handles deallocation. Returns 0 (upstream returns 0 on success).
ZSTD_freeDCtx
Port of ZSTD_freeDCtx. In the Rust port, dropping the Box frees.
ZSTD_getErrorCode
ZSTD_getErrorName
ZSTD_getErrorString
ZSTD_isError
compress
compress_bound
decompress
decompress_alloc
force_link
No-op function retained for link-propagation compatibility.
get_decompressed_size

Type Aliases§

ZSTD_DStream
Port of ZSTD_DStream. Upstream typedef ZSTD_DCtx ZSTD_DStream — same struct for both APIs.