Rate This Document
Findability
Accuracy
Completeness
Readability

API Description

KZstar supports only block compression and decompression algorithms and only compression levels 1 to 4. Other levels are processed as level 5. For details about the available APIs, see Table 1.

Table 1 Decompression algorithm APIs

API Definition

Description

Input Parameter

Return Value

size_t ZSTD_compressBound(size_t srcSize);

Calculates the maximum destination buffer size required after compression based on the input data size.

srcSize: input data size (in bytes)

Maximum number of bytes after compression, that is, the buffer size required for compression

unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize);

Obtains the original size of a compressed data frame.

  • src: data source, that is, the compressed data stream
  • srcSize: input data size (in bytes)

Content size (in bytes) of a compressed data frame

ZSTD_CCtx* ZSTD_createCCtx(void);

Creates and initializes a compression context, which is used to control parameters in the compression process.

-

Pointer to the compression context

size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx);

Releases the compression context created by ZSTD_createCCtx and related resources.

cctx: pointer to the compression context to be released

  • Success: 0 is returned.
  • Failure: A negative value is returned.

size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel);

Uses the given compression context cctx to compress data. The compression level is configurable.

  • cctx: compression context, including compression settings
  • dst: destination buffer for storing compressed data
  • dstCapacity: destination buffer capacity (in bytes)
  • src: input data, pointing to the data to be compressed
  • srcSize: input data size (in bytes)
  • compressionLevel: compression level, ranging from 1 to 22

Actual size of the data that is compressed

size_t ZSTD_compress(void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel);

Uses the default compression settings to compress data.

  • dst: destination buffer for storing compressed data
  • dstCapacity: destination buffer capacity (in bytes)
  • src: input data, pointing to the data to be compressed
  • srcSize: input data size (in bytes)
  • compressionLevel: compression level, ranging from 1 to 22

Actual size of the data that is compressed

ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem);

Creates a decompression context and allows custom memory allocation and release functions to be passed in.

customMem: custom memory allocation function

Pointer to the decompression context

ZSTD_DCtx* ZSTD_createDCtx(void);

Creates and initializes a decompression context and uses the default memory allocation mode.

-

Pointer to the decompression context

size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx);

Releases the decompression context created by ZSTD_createDCtx or ZSTD_createDCtx_advanced.

dctx: pointer to the decompression context

  • Success: 0 is returned.
  • Failure: A negative value is returned.

size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);

Uses the created decompression context dctx to decompress the compressed data.

  • dctx: decompression context
  • dst: buffer for storing decompressed data
  • dstCapacity: size of the dst buffer (in bytes)
  • src: buffer for storing the input compressed data
  • srcSize: size of the input compressed data (in bytes)

Number of bytes after decompression. If an error occurs, a negative value is returned.

size_t ZSTD_decompress(void* dst, size_t dstCapacity, const void* src, size_t srcSize);

Uses the default decompression settings to decompress data.

  • dst: buffer for storing decompressed data
  • dstCapacity: size of the dst buffer (in bytes)
  • src: buffer for storing the input compressed data
  • srcSize: size of the input compressed data (in bytes)

Number of bytes after decompression. If an error occurs, a negative value is returned.