Thread: zlib stream buffer problem

  1. #1
    Registered User
    Join Date
    Jun 2010

    zlib stream buffer problem

    here's the 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);
    	zin.next_in = inputBuffer;
    	zin.next_out = outputBuffer;
    	while(zin.total_in != bytes && zin.total_out < 1024)
    		zin.avail_in = zin.avail_out = 1;
    	bytes = write(fdout,outputBuffer,zin.total_out);
    	printf("bytes written: %d\n",bytes);
    	return 0;
    I'm not looking to error check just yet, I'm just trying to get the deflation to work at all.
    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?

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Your code looks something like this:
    	char inputBuffer[MAXLINE;];
    	char outputBuffer[MAXLINE;];
    since you have a simi-colon in your #define. -- That's probably not good.

    Another thing is where do you tell zlib how much data to decompress? I've not used zlib, but I'm thinking you should set up the output size buffer FIRST within zlib.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File stream problem. PLEASE HELP
    By ellimist14 in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2009, 03:48 PM
  2. Simple (?) problem rendering a vertex buffer
    By Dark_Phoenix in forum Game Programming
    Replies: 4
    Last Post: 08-11-2007, 07:32 PM
  3. Having Buffer Problems With Overlapped I/O --
    By Sargera in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 04:46 PM
  4. stream socket problem
    By WL in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 11:07 PM
  5. Does anyone Know How to..?
    By kwigibo in forum C Programming
    Replies: 12
    Last Post: 09-20-2001, 08:16 AM