| 
 | 1 | +---  | 
 | 2 | +title: Basics  | 
 | 3 | +---  | 
 | 4 | +These are the basic helper functions that you need to interact with `zstd`.  | 
 | 5 | + | 
 | 6 | +## Error Checking  | 
 | 7 | + | 
 | 8 | +Any function that returns a `size_t` must be checked with `ZSTD_isError()`.  | 
 | 9 | + | 
 | 10 | +::: ZSTD_isError  | 
 | 11 | + | 
 | 12 | +If the function returned an error, then `ZSTD_getErrorName()` will return the error string.  | 
 | 13 | + | 
 | 14 | +::: ZSTD_getErrorName  | 
 | 15 | + | 
 | 16 | +## Compression Utilities  | 
 | 17 | + | 
 | 18 | +`ZSTD_compressBound()` returns the maximum possible compressed size of a given  | 
 | 19 | +input, which will be slightly larger than the input size. If you provide an  | 
 | 20 | +output buffer at least this large to [ZSTD_compress()][ZSTD_compress],  | 
 | 21 | +[ZSTD_compressCCtx()][ZSTD_compressCCtx], or [ZSTD_compress2()][ZSTD_compress2]  | 
 | 22 | +the compressed result is guaranteed to fit.  | 
 | 23 | + | 
 | 24 | +::: ZSTD_compressBound  | 
 | 25 | + | 
 | 26 | +## Decompression Utilities  | 
 | 27 | + | 
 | 28 | +`ZSTD_getFrameContentSize()` will return the (decompressed) content size of a  | 
 | 29 | +Zstandard or Skippable frame. If the content size is not known it will return  | 
 | 30 | +[ZSTD_CONTENTSIZE_UNKNOWN][], and if an error occurs it will return  | 
 | 31 | +[ZSTD_CONTENTSIZE_ERROR][].  | 
 | 32 | + | 
 | 33 | +???+ warning   | 
 | 34 | + | 
 | 35 | +    This only returns the content size of the first compressed frame in the  | 
 | 36 | +    compressed source. Zstd decompression functions like  | 
 | 37 | +    [ZSTD_decompress()][ZSTD_decompress] will decompress zero or more  | 
 | 38 | +    concatenated frames. So calling this function does not guarantee that  | 
 | 39 | +    decompression will have enough space, unless you know a-priori that there  | 
 | 40 | +    is only one compressed frame in the source.  | 
 | 41 | + | 
 | 42 | +::: ZSTD_getFrameContentSize  | 
 | 43 | + | 
 | 44 | +::: ZSTD_CONTENTSIZE_UNKNOWN  | 
 | 45 | +    options:  | 
 | 46 | +        show_description: false  | 
 | 47 | + | 
 | 48 | +::: ZSTD_CONTENTSIZE_ERROR  | 
 | 49 | +    options:  | 
 | 50 | +        show_description: false  | 
 | 51 | + | 
 | 52 | +`ZSTD_findFrameCompressedSize()` will return the compressed size of the Zstd  | 
 | 53 | +frame. This function can be useful if:  | 
 | 54 | + | 
 | 55 | +- You don't know the compressed size of the frame.  | 
 | 56 | +- There may be more than one compressed frame in the compressed source.  | 
 | 57 | + | 
 | 58 | +???+ note  | 
 | 59 | + | 
 | 60 | +    This function has to traverse the entire Zstd compressed frame, and read  | 
 | 61 | +    each block's header. It is cheap, given that there is normally one block  | 
 | 62 | +    for every 128 KiB of content, but it isn't free.  | 
 | 63 | + | 
 | 64 | +::: ZSTD_findFrameCompressedSize  | 
0 commit comments