Trisurf Monte Carlo simulator
Samo Penic
2019-10-18 842378276ab4c4a8dabd02324bb24b8da39c4384
src/snapshot.c
@@ -173,19 +173,27 @@
   return nbase;
}
char *ts_compress(char *data, ts_uint data_len, ts_uint original_len){
char *ts_compress(char *data, ts_uint data_len){
   size_t nbase1, nbase2;
   char *compr;
   size_t number_of_compressed_bytes=ts_compress_data(data, data_len, &compr);
   unsigned char *compr=(unsigned char *)malloc(data_len);
   size_t number_of_compressed_bytes=data_len;
   compress(compr,&number_of_compressed_bytes, (unsigned char *)data, data_len);
//   printf("Compressdion error code=%d, Z_OK=%d, Z_BUF_ERROR=%d", errcode, Z_OK, Z_BUF_ERROR);
   char *encoded_compressed=base64_encode((unsigned char *)compr,number_of_compressed_bytes,&nbase1);
   free(compr);
   ts_uint header[4]={1, original_len, original_len, number_of_compressed_bytes};
   ts_uint header[4]={1, data_len, data_len, number_of_compressed_bytes};
   char *encoded_header=(char *)base64_encode((unsigned char *)header, 4*sizeof(ts_uint), &nbase2);
   char *return_value=malloc((nbase1+nbase2+1)*sizeof(char));
   strncpy(return_value,encoded_header,nbase2);
   strncpy(return_value+nbase2,encoded_compressed,nbase1);
   *(return_value+nbase1+nbase2)=0;
   printf("Compressed size in bytes= %ld, size of encoded header= %ld, size of encoded compressed= %ld.\n",number_of_compressed_bytes, nbase2, nbase1);
//   printf("Compressed size in bytes= %ld, size of encoded header= %ld, size of encoded compressed= %ld.\n",number_of_compressed_bytes, nbase2, nbase1);
   free(encoded_compressed);
   free(encoded_header);
   return return_value;