Created
June 21, 2015 16:03
-
-
Save koooge/3bf42b464d928db781f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <zlib.h> | |
#define BUF_SIZE 1024 | |
int main(int argc, char **argv) | |
{ | |
int ret = Z_OK; | |
z_stream strm; | |
Byte *ibuf, *obuf; | |
FILE *ifp = fopen("input.txt", "r"); | |
FILE *ofp = fopen("output.gz", "w"); | |
ibuf = (Byte *)calloc(BUF_SIZE, sizeof(Byte)); | |
obuf = (Byte *)calloc(BUF_SIZE, sizeof(Byte)); | |
fread(ibuf, BUF_SIZE, 1, ifp); | |
strm.zalloc = Z_NULL; | |
strm.zfree = Z_NULL; | |
strm.opaque = Z_NULL; | |
ret = deflateInit2(&strm, 6, Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY); | |
strm.next_in = ibuf; | |
strm.avail_in = BUF_SIZE; | |
strm.next_out = obuf; | |
strm.avail_out = BUF_SIZE; | |
ret = deflate(&strm, Z_FINISH); | |
fwrite(obuf, strm.total_out, 1, ofp); | |
END: | |
deflateEnd(&strm); | |
fclose(ofp); | |
fclose(ifp); | |
return 0; | |
} | |
~ |
Author
koooge
commented
Jun 21, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment