ZSTD_compressStream2()
Behaves like ZSTD_compressStream with additional control over end directives. This is the recommended streaming compression function since v1.4.0+.Compression context created with
ZSTD_createCCtx()Output buffer structure. The function updates
output->pos to indicate how much data was writtenInput buffer structure. The function updates
input->pos to indicate how much data was consumedCompression directive:
ZSTD_e_continue- Collect more data, optimal compression ratioZSTD_e_flush- Flush any data provided so far, creates decodable blocksZSTD_e_end- Flush remaining data and close current frame
Returns
- Returns a minimum amount of data remaining to be flushed from internal buffers
- For
ZSTD_e_end, returns 0 when the frame is completely flushed - Returns an error code if it fails (test with
ZSTD_isError())
Usage
When
nbWorkers==0 (default), the function is blocking and completes before returning. When nbWorkers>=1, the function is non-blocking and distributes work to internal threads.ZSTD_CStreamInSize()
Returns the recommended size for the input buffer.Returns
Recommended size for input buffer in bytes. This is not required but helps optimize performance by reducing memory shuffling and buffering.Usage
These buffer sizes are recommendations, not requirements.
ZSTD_compressStream2() accepts any buffer size for both input and output.