here's the code
I'm not looking to error check just yet, I'm just trying to get the deflation to work at all.Code:#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <zlib.h> #include <string.h> #include <unistd.h> #define MAXLINE 1024; int main(int argc, char *argv[]) { int fdin,fdout,status; int count; char inputBuffer[MAXLINE]; char outputBuffer[MAXLINE]; struct z_stream_s zin; size_t bytes; if(argc != 3) { fprintf(stderr,"usage: zcomp infile outfile"); return 0; } if((fdin = open(argv[1],O_RDONLY))<0) { fprintf(stderr,"open() failed\n%s\n",argv[1]); return 0; } if((fdout = open(argv[2],O_RDWR | O_CREAT))<0) { fprintf(stderr,"open() failed\n%s\n",argv[2]); return 0; } bytes = read(fdin,inputBuffer,1024); deflateInit(&zin,Z_DEFAULT_COMPRESSION); zin.next_in = inputBuffer; zin.next_out = outputBuffer; while(zin.total_in != bytes && zin.total_out < 1024) { zin.avail_in = zin.avail_out = 1; deflate(&zin,Z_NO_FLUSH); } bytes = write(fdout,outputBuffer,zin.total_out); printf("bytes written: %d\n",bytes); deflateEnd(&zin); close(fdin); close(fdout); return 0; }
I run the program on a 744 BYTE source code file and the output is 2 bytes, I can't trace the problem.
Anyone have any ideas?



LinkBack URL
About LinkBacks


