Class Zstd

java.lang.Object
dev.freya02.discord.zstd.ffm.Zstd

public final class Zstd extends Object
Streaming decompression - HowTo

A ZSTD_DStream object is required to track streaming operations. Use ZSTD_createDStream() and ZSTD_freeDStream(MemorySegment) to create/release resources. ZSTD_DStream objects can be re-employed multiple times.

Use ZSTD_initDStream(MemorySegment) to start a new decompression operation. - return : recommended first input size

Alternatively, use advanced API to set specific properties.

Use ZSTD_decompressStream(MemorySegment, MemorySegment, MemorySegment) repetitively to consume your input. The function will update both pos fields. If input.pos < input.size, some input has not been consumed. It's up to the caller to present again remaining data.

The function tries to flush all data decoded immediately, respecting output buffer size. If output.pos < output.size, decoder has flushed everything it could.

However, when output.pos == output.size, it's more difficult to know. If @return > 0, the frame is not complete, meaning either there is still some data left to flush within internal buffers, or there is more input to read to complete the frame (or both). In which case, call ZSTD_decompressStream(MemorySegment, MemorySegment, MemorySegment) again to flush whatever remains in the buffer. Note : with no additional input provided, amount of data flushed is necessarily <= 131072. - return : 0 when a frame is completely decoded and fully flushed, or an error code, which can be tested using ZSTD_isError(long), or any other value > 0, which means there is still some decoding or flushing to do to complete current frame : the return value is a suggested next input size (just a hint for better latency) that will never request more than the remaining content of the compressed frame.

  • Field Details

  • Method Details

    • ZSTD_getErrorString

      public static MemorySegment ZSTD_getErrorString(int code)
      const char *ZSTD_getErrorString(ZSTD_ErrorCode code)
      
    • ZSTD_versionString

      public static MemorySegment ZSTD_versionString()
      const char *ZSTD_versionString()
      
    • ZSTD_isError

      public static int ZSTD_isError(long result)
      unsigned int ZSTD_isError(size_t result)
      
    • ZSTD_getErrorName

      public static MemorySegment ZSTD_getErrorName(long result)
      const char *ZSTD_getErrorName(size_t result)
      
    • ZSTD_createDStream

      public static MemorySegment ZSTD_createDStream()
      ZSTD_DStream *ZSTD_createDStream()
      
    • ZSTD_freeDStream

      public static long ZSTD_freeDStream(MemorySegment zds)
      size_t ZSTD_freeDStream(ZSTD_DStream *zds)
      
    • ZSTD_initDStream

      public static long ZSTD_initDStream(MemorySegment zds)
      Initialize/reset DStream state for new decompression operation. Call before new decompression operation using same DStream.

      Note : This function is redundant with the advanced API and equivalent to:

      ZSTD_DCtx_reset(zds, ZSTD_reset_session_only);
      ZSTD_DCtx_refDDict(zds, NULL);
      

         size_t ZSTD_initDStream(ZSTD_DStream *zds)
      
    • ZSTD_decompressStream

      public static long ZSTD_decompressStream(MemorySegment zds, MemorySegment output, MemorySegment input)
      Streaming decompression function.

      Call repetitively to consume full input updating it as necessary.

      Function will update both input and output pos fields exposing current state via these fields:

      • input.pos < input.size, some input remaining and caller should provide remaining input on the next call.
      • output.pos < output.size, decoder flushed internal output buffer.
      • output.pos == output.size, unflushed data potentially present in the internal buffers, check ZSTD_decompressStream() @return value, if > 0, invoke it again to flush remaining data to output.

      Note : with no additional input, amount of data flushed <= 131072.

      Note: when an operation returns with an error code, the zds state may be left in undefined state. It's UB to invoke ZSTD_decompressStream() on such a state. In order to re-use such a state, it must be first reset, which can be done explicitly (ZSTD_DCtx_reset()), or is implied for operations starting some new decompression job (ZSTD_initDStream, ZSTD_decompressDCtx(), ZSTD_decompress_usingDict())

      Returns:
      0 when a frame is completely decoded and fully flushed, or an error code, which can be tested using ZSTD_isError(long), or any other value > 0, which means there is some decoding or flushing to do to complete current frame.

      size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
      
    • ZSTD_DStreamOutSize

      public static long ZSTD_DStreamOutSize()