Compress-Zstd

 view release on metacpan or  search on metacpan

ext/zstd/doc/zstd_manual.html  view on Meta::CPAN

                const void* src, size_t srcSize,
                      int compressionLevel);
</b><p>  Compresses `src` content as a single zstd compressed frame into already allocated `dst`.
  Hint : compression runs faster if `dstCapacity` >=  `ZSTD_compressBound(srcSize)`.
  @return : compressed size written into `dst` (<= `dstCapacity),
            or an error code if it fails (which can be tested using ZSTD_isError()). 
</p></pre><BR>

<pre><b>size_t ZSTD_decompress( void* dst, size_t dstCapacity,
                  const void* src, size_t compressedSize);
</b><p>  `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames.
  `dstCapacity` is an upper bound of originalSize to regenerate.
  If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data.
  @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
            or an errorCode if it fails (which can be tested using ZSTD_isError()). 
</p></pre><BR>

<pre><b>#define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1)
#define ZSTD_CONTENTSIZE_ERROR   (0ULL - 2)
unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize);
</b><p>  `src` should point to the start of a ZSTD encoded frame.
  `srcSize` must be at least as large as the frame header.
            hint : any size >= `ZSTD_frameHeaderSize_max` is large enough.
  @return : - decompressed size of `src` frame content, if known
            - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined
            - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small)
   note 1 : a 0 return value means the frame is valid but "empty".
   note 2 : decompressed size is an optional field, it may not be present, typically in streaming mode.
            When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size.
            In which case, it's necessary to use streaming mode to decompress data.
            Optionally, application can rely on some implicit limit,
            as ZSTD_decompress() only needs an upper bound of decompressed size.
            (For example, data could be necessarily cut into blocks <= 16 KB).
   note 3 : decompressed size is always present when compression is completed using single-pass functions,
            such as ZSTD_compress(), ZSTD_compressCCtx() ZSTD_compress_usingDict() or ZSTD_compress_usingCDict().
   note 4 : 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.
   note 5 : 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.
   note 6 : This function replaces ZSTD_getDecompressedSize() 
</p></pre><BR>

<pre><b>unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
</b><p>  NOTE: This function is now obsolete, in favor of ZSTD_getFrameContentSize().
  Both functions work the same way, but ZSTD_getDecompressedSize() blends
  "empty", "unknown" and "error" results to the same return value (0),
  while ZSTD_getFrameContentSize() gives them separate return values.
 @return : decompressed size of `src` frame content _if known and not empty_, 0 otherwise. 
</p></pre><BR>

<pre><b>size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
</b><p> `src` should point to the start of a ZSTD frame or skippable frame.
 `srcSize` must be >= first frame size
 @return : the compressed size of the first frame starting at `src`,
           suitable to pass as `srcSize` to `ZSTD_decompress` or similar,
        or an error code if input is invalid 
</p></pre><BR>

<h3>Helper functions</h3><pre></pre><b><pre>#define ZSTD_COMPRESSBOUND(srcSize)   ((srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) </b>/* margin, from 64 to 0 */ : 0))  /* this formula ensures that bound(A) + b...
size_t      ZSTD_compressBound(size_t srcSize); </b>/*!< maximum compressed size in worst case single-pass scenario */<b>
unsigned    ZSTD_isError(size_t code);          </b>/*!< tells if a `size_t` function result is an error code */<b>
const char* ZSTD_getErrorName(size_t code);     </b>/*!< provides readable string from an error code */<b>
int         ZSTD_minCLevel(void);               </b>/*!< minimum negative compression level allowed */<b>
int         ZSTD_maxCLevel(void);               </b>/*!< maximum compression level available */<b>
</pre></b><BR>
<a name="Chapter4"></a><h2>Explicit context</h2><pre></pre>

<h3>Compression context</h3><pre>  When compressing many times,
  it is recommended to allocate a context just once,
  and re-use it for each successive compression operation.
  This will make workload friendlier for system's memory.
  Note : re-using context is just a speed / resource optimization.
         It doesn't change the compression ratio, which remains identical.
  Note 2 : In multi-threaded environments,
         use one different context per thread for parallel execution.
 
</pre><b><pre>typedef struct ZSTD_CCtx_s ZSTD_CCtx;
ZSTD_CCtx* ZSTD_createCCtx(void);
size_t     ZSTD_freeCCtx(ZSTD_CCtx* cctx);
</pre></b><BR>
<pre><b>size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
                         void* dst, size_t dstCapacity,
                   const void* src, size_t srcSize,
                         int compressionLevel);
</b><p>  Same as ZSTD_compress(), using an explicit ZSTD_CCtx
  The function will compress at requested compression level,
  ignoring any other parameter 
</p></pre><BR>

<h3>Decompression context</h3><pre>  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. 
</pre><b><pre>typedef struct ZSTD_DCtx_s ZSTD_DCtx;
ZSTD_DCtx* ZSTD_createDCtx(void);
size_t     ZSTD_freeDCtx(ZSTD_DCtx* dctx);
</pre></b><BR>
<pre><b>size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
                           void* dst, size_t dstCapacity,
                     const void* src, size_t srcSize);
</b><p>  Same as ZSTD_decompress(),
  requires an allocated ZSTD_DCtx.
  Compatible with sticky parameters.
 
</p></pre><BR>

<a name="Chapter5"></a><h2>Advanced compression API</h2><pre></pre>

<pre><b>typedef enum { ZSTD_fast=1,
               ZSTD_dfast=2,
               ZSTD_greedy=3,
               ZSTD_lazy=4,
               ZSTD_lazy2=5,
               ZSTD_btlazy2=6,
               ZSTD_btopt=7,
               ZSTD_btultra=8,
               ZSTD_btultra2=9
               </b>/* note : new strategies _might_ be added in the future.<b>



( run in 0.482 second using v1.01-cache-2.11-cpan-39bf76dae61 )