kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

use_miniz.c (1084B)


      1 /* use_miniz.c — exercise miniz deflate/inflate round-trips + CRC-32.
      2  * Deterministic output. */
      3 #include "miniz.h"
      4 #include <stdio.h>
      5 #include <string.h>
      6 
      7 int main(void) {
      8   const char *msg =
      9       "miniz round-trip: hello hello hello world world 12341234 abcabcabc";
     10   size_t n = strlen(msg);
     11 
     12   unsigned char comp[512];
     13   unsigned char dec[512];
     14   mz_ulong cl = sizeof comp;
     15   mz_ulong dl = sizeof dec;
     16 
     17   int rc = mz_compress(comp, &cl, (const unsigned char *)msg, n);
     18   if (rc != MZ_OK) {
     19     printf("compress-fail %d\n", rc);
     20     return 1;
     21   }
     22   rc = mz_uncompress(dec, &dl, comp, cl);
     23   if (rc != MZ_OK) {
     24     printf("uncompress-fail %d\n", rc);
     25     return 1;
     26   }
     27 
     28   int match = (dl == n) && (memcmp(msg, dec, n) == 0);
     29   printf("in=%lu comp=%lu out=%lu match=%d\n", (unsigned long)n,
     30          (unsigned long)cl, (unsigned long)dl, match);
     31 
     32   mz_ulong crc = mz_crc32(MZ_CRC32_INIT, (const unsigned char *)msg, n);
     33   printf("crc32=%08lx\n", (unsigned long)crc);
     34   printf("adler-of-deflate=%lu\n",
     35          (unsigned long)mz_adler32(MZ_ADLER32_INIT, comp, cl));
     36   return 0;
     37 }