Skip to content

Instantly share code, notes, and snippets.

@ku
Created October 23, 2008 10:04
Show Gist options
  • Save ku/18979 to your computer and use it in GitHub Desktop.
Save ku/18979 to your computer and use it in GitHub Desktop.
gzip deflate
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <zlib.h>
#define BFSIZE (32 * 1024)
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage : %s filename\n", argv[0]);
exit(1);
}
const char* file = argv[1];
FILE *src = fopen(file, "rb");
FILE *raw = fopen("out", "wb");
//FILE *dst = fopen(out, "rb");
unsigned char bf[BFSIZE];
unsigned char compressed[BFSIZE];
unsigned int n ;
unsigned long m;
while ( n = fread (bf, 1, BFSIZE, src) ) {
m = BFSIZE;
fwrite(bf, 1, n , raw);
int result = uncompress(compressed, &m, bf, n);
if (result != Z_OK) {
fprintf(stderr, "err: %d\n", result);
} else {
fprintf(stderr, "m: %d\n", m);
fwrite(compressed, 1, m , stdout);
}
//fwrite(bf, 1, n , stdout);
}
fclose(raw);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment