class

Zstd::Decompress::Context

Inherits Zstd::Context / Reference / Object

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.

Constants

CONTENT_SIZE_ERROR = 0_u64 &- 2

Constructors

new(*, dict : Zstd::Dict | Nil = nil)
Source

Instance methods

decompress(src : Bytes, dst : Bytes | Nil = nil) : Bytes

Returns decompressed Bytes

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

Source
dict
Source
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".

Source
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.
Source
memsize

Give the current memory usage of zstd context.

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

Source

Nested types