#include <stdio.h>
#include "zlib.h"
int def(FILE *source, FILE *dest, int level);
int inf(FILE *source, FILE *dest);
void zerr(int ret);
int compressFile(const char* infilename, const char* outfilename)
{
FILE* infile = fopen(infilename, "rb");
if (infile == NULL) {
fputs("error opening input file", stderr);
return 1;
}
FILE* outfile = fopen(outfilename, "wb");
if (outfile == NULL) {
fputs("error opening output file", stderr);
return 1;
}
int ret = def(infile, outfile, Z_BEST_COMPRESSION);
if (ret != Z_OK)
zerr(ret);
if (fclose(infile)) {
fputs("error closing input file", stderr);
return 1;
}
if (fclose(outfile)) {
fputs("error closing output file", stderr);
return 1;
}
return ret;
}
int decompressFile(const char* infilename, const char* outfilename)
{
FILE* infile = fopen(infilename, "rb");
if (infile == NULL) {
fputs("error opening input file", stderr);
return 1;
}
FILE* outfile = fopen(outfilename, "wb");
if (outfile == NULL) {
fputs("error opening output file", stderr);
return 1;
}
int ret = inf(infile, outfile);
if (ret != Z_OK)
zerr(ret);
if (fclose(infile)) {
fputs("error closing input file", stderr);
return 1;
}
if (fclose(outfile)) {
fputs("error closing output file", stderr);
return 1;
}
return ret;
}