Skip to content

Instantly share code, notes, and snippets.

@oatmealraisin
Created July 5, 2018 21:37
Show Gist options
  • Save oatmealraisin/be72e7035b6436a2abc016ebdc3d907a to your computer and use it in GitHub Desktop.
Save oatmealraisin/be72e7035b6436a2abc016ebdc3d907a to your computer and use it in GitHub Desktop.
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <zlib.h>
#define CHUNK 16384
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
#else
# define SET_BINARY_MODE(file)
#endif
unsigned char decompressGzip(const char *gzFileName, const char *destFileName) {
gzFile gzf = gzopen(gzFileName, "rb");
FILE *destFile = fopen(destFileName, "wb");
SET_BINARY_MODE(gzf);
char buffer[CHUNK];
int num_read = 0;
int total_read = 0;
while((num_read = gzread(gzf, buffer, sizeof(buffer))) > 0) {
printf("Num read %d\n", num_read);
total_read += num_read;
if(num_read != fwrite(buffer, 1, num_read, destFile)) printf("Something");
}
printf("Total read: %d\n", total_read);
printf("EOF %d\n", gzeof(gzf));
gzclose(gzf);
fclose(destFile);
//remove(gzFileName);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment