| 28 | |
| 29 | |
| 30 | static 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 | |
| 59 | static char* createOutFilename_orDie(const char* filename) |