Quantcast
Viewing all articles
Browse latest Browse all 21

Answer by user885074 for need an example on easyzlib (how to compress and decompress strings sent in the argv from command line Windows/Linux)

ezcompress and ezuncompress work on the file data directly which are represented as arrays of characters.

for (int i = 1; i < argc; i++) {    // open argument you want to compress    FILE *inputFile = fopen(argv[i], "r");    // get length of input    // http://stackoverflow.com/questions/238603/how-can-i-get-a-files-size-in-c    fseek(inputFile, 0, SEEK_END);    size_t inputSize = ftell(inputFile);    fseek(inputFile, 0, SEEK_SET);    unsigned char *inputBuffer = (unsigned char *)malloc(inputSize);    fread(inputBuffer, 1, inputSize, inputFile);    long outputSize = EZ_COMPRESSMAXDESTLENGTH(sz);    unsigned char *outputBuffer = (unsigned char *)malloc(outputSize);    int result = ezcompress(outputBuffer, &outputSize, inputBuffer, inputSize);    if (result != EZ_BUF_ERROR) {        // Do stuff with outputBuffer which has length outputSize    } else {        // Something went wrong    }    free(intputBuffer);    free(outputBuffer);}

Viewing all articles
Browse latest Browse all 21

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>