MCPcopy Create free account
hub / github.com/F-Stack/f-stack / decompress

Function decompress

freebsd/contrib/zstd/examples/simple_decompression.c:16–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#include "common.h" // Helper functions, CHECK(), and CHECK_ZSTD()
15
16static void decompress(const char* fname)
17{
18 size_t cSize;
19 void* const cBuff = mallocAndLoadFile_orDie(fname, &cSize);
20 /* Read the content size from the frame header. For simplicity we require
21 * that it is always present. By default, zstd will write the content size
22 * in the header when it is known. If you can't guarantee that the frame
23 * content size is always written into the header, either use streaming
24 * decompression, or ZSTD_decompressBound().
25 */
26 unsigned long long const rSize = ZSTD_getFrameContentSize(cBuff, cSize);
27 CHECK(rSize != ZSTD_CONTENTSIZE_ERROR, "%s: not compressed by zstd!", fname);
28 CHECK(rSize != ZSTD_CONTENTSIZE_UNKNOWN, "%s: original size unknown!", fname);
29
30 void* const rBuff = malloc_orDie((size_t)rSize);
31
32 /* Decompress.
33 * If you are doing many decompressions, you may want to reuse the context
34 * and use ZSTD_decompressDCtx(). If you want to set advanced parameters,
35 * use ZSTD_DCtx_setParameter().
36 */
37 size_t const dSize = ZSTD_decompress(rBuff, rSize, cBuff, cSize);
38 CHECK_ZSTD(dSize);
39 /* When zstd knows the content size, it will error if it doesn't match. */
40 CHECK(dSize == rSize, "Impossible because zstd will check this condition!");
41
42 /* success */
43 printf("%25s : %6u -> %7u \n", fname, (unsigned)cSize, (unsigned)rSize);
44
45 free(rBuff);
46 free(cBuff);
47}
48
49int main(int argc, const char** argv)
50{

Callers 5

mainFunction · 0.70
test_buf_to_bufFunction · 0.50
test_buf_to_cbFunction · 0.50
test_cb_to_cbFunction · 0.50
test_cb_to_bufFunction · 0.50

Calls 6

mallocAndLoadFile_orDieFunction · 0.85
malloc_orDieFunction · 0.85
ZSTD_getFrameContentSizeFunction · 0.50
ZSTD_decompressFunction · 0.50
printfFunction · 0.50
freeFunction · 0.50

Tested by 4

test_buf_to_bufFunction · 0.40
test_buf_to_cbFunction · 0.40
test_cb_to_cbFunction · 0.40
test_cb_to_bufFunction · 0.40