class Zstd::Decompress::Context

Overview

Usage:

cctx = Zstd::Deompress::Context.new
dbuf = cctx.compress cbuf

When decompressing many times, it is recommended to allocate a context only once, and re-use it for each successive compression operation. This will make workload friendlier for system's memory. Use one context per thread for parallel execution.

Defined in:

Constant Summary

CONTENT_SIZE_ERROR = 0_u64 &- 2

Constructors

Instance Method Summary

Instance methods inherited from class Zstd::Context

close close, dup dup, finalize finalize

Constructor Detail

def self.new(*, dict : Zstd::Dict? = nil) #

Instance Method Detail

def decompress(src : Bytes, dst : Bytes? = nil) : Bytes #

Returns decompressed Bytes

dst is an optional output buffer that must be >= frame_content_size


def dict : Zstd::Dict? #

def dict=(d : Zstd::Dict) #

Reference a prepared dictionary, to be used to decompress next frames. The dictionary remains active for decompression of future frames using same DCtx. Currently, only one dictionary can be managed.

Referencing a new dictionary effectively "discards" any previous one. Referencing a nil Dict means "return to no-dictionary mode".


def frame_content_size(src : Bytes) #

https://facebook.github.io/zstd/zstd_manual.html#Chapter6 Returns the frame content size if known.

Notes:

  • Always available when using single pass compression.
  • Not available if compressed using streaming mode.
  • decompressed size can be very large (64-bits value), potentially larger than what local system can handle as a single memory segment. In which case, it's necessary to use streaming mode to decompress data.
  • If source is untrusted, decompressed size could be wrong or intentionally modified. Always ensure return value fits within application's authorized limits. Each application can set its own limits.

def memsize #

Give the current memory usage of zstd context.

Note that object memory usage can evolve (increase or decrease) over time.