#include #include #include #include #include uint8_t data[1 * 1024 * 1024]; int main(int argc, char **argv) { z_stream strm = {0}; uint8_t *buf; uint32_t count; uint32_t bound; count = fread(data, 1, sizeof data, stdin); if (count <= 0) { warnx("no data was provided, so cannot deflate"); return 0; } deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15, 1, Z_FIXED); bound = deflateBound(&strm, count); buf = malloc(bound); strm.avail_out = bound; strm.next_out = buf; strm.next_in = data; strm.avail_in = count; deflate(&strm, Z_FINISH); deflateEnd(&strm); free(buf); return 0; }