| 15 | #include "common.h" // Helper functions, CHECK(), and CHECK_ZSTD() |
| 16 | |
| 17 | static void compress_orDie(const char* fname, const char* oname) |
| 18 | { |
| 19 | size_t fSize; |
| 20 | void* const fBuff = mallocAndLoadFile_orDie(fname, &fSize); |
| 21 | size_t const cBuffSize = ZSTD_compressBound(fSize); |
| 22 | void* const cBuff = malloc_orDie(cBuffSize); |
| 23 | |
| 24 | /* Compress. |
| 25 | * If you are doing many compressions, you may want to reuse the context. |
| 26 | * See the multiple_simple_compression.c example. |
| 27 | */ |
| 28 | size_t const cSize = ZSTD_compress(cBuff, cBuffSize, fBuff, fSize, 1); |
| 29 | CHECK_ZSTD(cSize); |
| 30 | |
| 31 | saveFile_orDie(oname, cBuff, cSize); |
| 32 | |
| 33 | /* success */ |
| 34 | printf("%25s : %6u -> %7u - %s \n", fname, (unsigned)fSize, (unsigned)cSize, oname); |
| 35 | |
| 36 | free(fBuff); |
| 37 | free(cBuff); |
| 38 | } |
| 39 | |
| 40 | static char* createOutFilename_orDie(const char* filename) |
| 41 | { |
no test coverage detected