Skip to content

Commit cfcb233

Browse files
committed
Make example of ZSTD_compress()
1 parent c0df9ba commit cfcb233

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/zstd.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,21 @@ ZSTDLIB_API const char* ZSTD_versionString(void);
151151
/***************************************
152152
* Simple Core API
153153
***************************************/
154-
/*! ZSTD_compress() :
155-
* Compresses `src` content as a single zstd compressed frame into already allocated `dst`.
156-
* NOTE: Providing `dstCapacity >= ZSTD_compressBound(srcSize)` guarantees that zstd will have
157-
* enough space to successfully compress the data.
158-
* @return : compressed size written into `dst` (<= `dstCapacity),
159-
* or an error code if it fails (which can be tested using ZSTD_isError()). */
154+
/*!
155+
* Compresses @p src using the given @p compressionLevel and writes the result into @p dst.
156+
*
157+
* @param src The data to compress of size @p srcSize.
158+
* @param dst The output buffer of isze @p dstCapacity.
159+
*
160+
* @returns The compressed size or an error that can be checked with [ZSTD_isError()][ZSTD_isError].
161+
*
162+
* @note Compression is guaranteed to succeed (with the exception of OOMs) if
163+
* @p dstCapacity is at least `ZSTD_compressBound(srcSize)`.
164+
*
165+
* @note It is common to use @p srcSize as the @p dstCapacity. In this case you should check to see
166+
* if `ZSTD_isError(ret) && ZSTD_getErrorCode(ret) == ZSTD_error_dstSize_tooSmall` then the
167+
* @p src wasn't compressible.
168+
*/
160169
ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity,
161170
const void* src, size_t srcSize,
162171
int compressionLevel);

0 commit comments

Comments
 (0)