Class: RZstd::FrameCodec
- Inherits:
-
Object
- Object
- RZstd::FrameCodec
- Defined in:
- lib/rzstd/frame_codec.rb
Class Method Summary collapse
-
.new(dict: nil, level: DEFAULT_LEVEL) ⇒ Object
Frame-format Zstd codec, optionally dict-bound.
Instance Method Summary collapse
-
#decompress(bytes, max_output_size: nil) ⇒ Object
Bounded single-shot decompression.
Class Method Details
.new(dict: nil, level: DEFAULT_LEVEL) ⇒ Object
Frame-format Zstd codec, optionally dict-bound. Holds a CCtx and DCtx, each behind a Mutex — the whole reason rzstd exists is to avoid allocating ~256 KiB of ZSTD_*Ctx state per call. Hold the codec across many compress/decompress calls to amortise that.
level is set once at construction and baked into the CCtx;
changing level means building a new codec (like dict:).
Shareable across Ractors via the interior Mutexes. For parallel throughput, give each Ractor its own FrameCodec.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rzstd/frame_codec.rb', line 24 def self.new(dict: nil, level: DEFAULT_LEVEL) case dict when nil _native_new(nil, 0, Integer(level)) when Dictionary _native_new(dict.bytes, dict.id, Integer(level)) when String d = Dictionary.new(bytes: dict) _native_new(d.bytes, d.id, Integer(level)) else raise TypeError, "expected RZstd::Dictionary, String, or nil; got #{dict.class}" end end |
Instance Method Details
#decompress(bytes, max_output_size: nil) ⇒ Object
Bounded single-shot decompression. When max_output_size: is given,
the Rust extension reads the frame's Frame_Content_Size header,
raises MissingContentSizeError if absent, and raises
OutputSizeLimitError if the declared size exceeds the limit —
all before allocating the output buffer or invoking the decoder.
When nil, frames without FCS fall back to a 1 MiB ceiling.
45 46 47 |
# File 'lib/rzstd/frame_codec.rb', line 45 def decompress(bytes, max_output_size: nil) _native_decompress(bytes, Integer(max_output_size || 0)) end |