From 6c63633545c254dc085402e0f927a6826d1dd229 Mon Sep 17 00:00:00 2001 From: Akinori Ito Date: Fri, 9 Nov 2001 04:59:17 +0000 Subject: Updates from 0.2.1 into 0.2.1-inu-1.5 --- deflate.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 deflate.c (limited to 'deflate.c') diff --git a/deflate.c b/deflate.c new file mode 100644 index 0000000..0464cc6 --- /dev/null +++ b/deflate.c @@ -0,0 +1,58 @@ + +#include +#include +#include + +#undef BUFSIZE +#define BUFSIZE 4096 + +int +main(int argc, char **argv) +{ + z_stream s; + FILE *f; + char inbuf[BUFSIZE], outbuf[BUFSIZE]; + int status, flush; + + if (argc > 1) { + f = fopen(argv[1], "rb"); + if (! f) + exit(1); + } else + f = stdin; + + s.zalloc = Z_NULL; + s.zfree = Z_NULL; + s.opaque = Z_NULL; + status = deflateInit(&s, Z_DEFAULT_COMPRESSION); + if (status != Z_OK) + exit(1); + s.avail_in = 0; + s.next_out = outbuf; + s.avail_out = sizeof(outbuf); + flush = Z_NO_FLUSH; + while (1) { + if (s.avail_in == 0) { + s.next_in = inbuf; + s.avail_in = fread(inbuf, 1, sizeof(inbuf), f); + if (s.avail_in < sizeof(inbuf)) + flush = Z_FINISH; + } + status = deflate(&s, flush); + if (status == Z_STREAM_END) { + if (sizeof(outbuf) - s.avail_out) + fwrite(outbuf, 1, sizeof(outbuf) - s.avail_out, stdout); + break; + } + if (status != Z_OK) + exit(1); + if (s.avail_out == 0) { + fwrite(outbuf, 1, sizeof(outbuf), stdout); + s.next_out = outbuf; + s.avail_out = sizeof(outbuf); + } + } + deflateEnd(&s); + fclose(f); + return 0; +} -- cgit v1.2.3