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

Function compress

freebsd/contrib/zstd/examples/dictionary_compression.c:30–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28
29
30static void compress(const char* fname, const char* oname, const ZSTD_CDict* cdict)
31{
32 size_t fSize;
33 void* const fBuff = mallocAndLoadFile_orDie(fname, &fSize);
34 size_t const cBuffSize = ZSTD_compressBound(fSize);
35 void* const cBuff = malloc_orDie(cBuffSize);
36
37 /* Compress using the dictionary.
38 * This function writes the dictionary id, and content size into the header.
39 * But, it doesn't use a checksum. You can control these options using the
40 * advanced API: ZSTD_CCtx_setParameter(), ZSTD_CCtx_refCDict(),
41 * and ZSTD_compress2().
42 */
43 ZSTD_CCtx* const cctx = ZSTD_createCCtx();
44 CHECK(cctx != NULL, "ZSTD_createCCtx() failed!");
45 size_t const cSize = ZSTD_compress_usingCDict(cctx, cBuff, cBuffSize, fBuff, fSize, cdict);
46 CHECK_ZSTD(cSize);
47
48 saveFile_orDie(oname, cBuff, cSize);
49
50 /* success */
51 printf("%25s : %6u -> %7u - %s \n", fname, (unsigned)fSize, (unsigned)cSize, oname);
52
53 ZSTD_freeCCtx(cctx); /* never fails */
54 free(fBuff);
55 free(cBuff);
56}
57
58
59static char* createOutFilename_orDie(const char* filename)

Callers 4

mainFunction · 0.70
zstd_zlibwrapper.cFile · 0.50
test_compressFunction · 0.50
test_compressFunction · 0.50

Calls 9

mallocAndLoadFile_orDieFunction · 0.85
malloc_orDieFunction · 0.85
saveFile_orDieFunction · 0.85
ZSTD_compressBoundFunction · 0.50
ZSTD_createCCtxFunction · 0.50
ZSTD_compress_usingCDictFunction · 0.50
printfFunction · 0.50
ZSTD_freeCCtxFunction · 0.50
freeFunction · 0.50

Tested by 2

test_compressFunction · 0.40
test_compressFunction · 0.40