Jonah KIM
Jonah KIM

Reputation: 23

How can I calculate ZSTD_compressed file size in C?

void compresszstd(const char *input,const char *output) {

//

  size_t const fBuff_size = (size_t)fileSize; //input file size
  void *const fBuff = malloc(fBuff_size); //input file buff

  size_t const cBuff_size = ZSTD_compressBound(fBuff_size); // compressed size
  void *const cBuff = malloc(cBuff_size);// compressed data

// compress input buff and get size of compressed file
  size_t const c_size = ZSTD_compress(cBuff, cBuff_size, fBuff, fBuff_size, 1);

  fwrite(&cBuff, 1, c_size, output);

  fprintf(stdout, "%u\n%u\n", (unsigned)fBuff_size, (unsigned)c_size);

}

I tried to use zstd compress. When I compress test.txt which contains,

LWpSxCFgUh BmmJnEHaYG urlMrzBDFW jkYpByALnm UVaOzGwWkO pUmAAglAnE AXDeSGPpFe IrIItGYEwC pOrhUHPsMh IdtdfAofXN eRZLTEirRt OQkrVFtqfY JEQFixzifR dwreUUZYVV EkrIobWWfQ oCfdaXrlPi WGopEbfHGy bSxtEulqWH OuualBJWHa XVsqhFTECO

I need to get the size of the file before compression and the size of the file after zstd compression. So the size of before and after should be 220 and 194, but I get 220 and 18. Does anyone know what is problem?

Upvotes: 0

Views: 362

Answers (0)

Related Questions