The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to compress .zlib file wrapster UNIX for Advanced & Expert Users 1 05-04-2008 11:52 PM
problem about using zlib to uncompress gzip in memory iwishfine High Level Programming 0 03-24-2007 10:56 PM
uncompress big123456 UNIX for Advanced & Expert Users 3 11-20-2006 09:42 PM
rsh and uncompress and tar big123456 Shell Programming and Scripting 4 05-27-2005 06:44 AM
Uncompress... me!!!!!! :) gussiglo21 UNIX for Dummies Questions & Answers 3 12-10-2003 07:43 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 08-28-2006
Registered User
 

Join Date: Nov 2005
Posts: 15
uncompress of zlib

When I gzopen & gzread from a gzip file, it works OK. But I when I try to uncompress the same data from memory (either by reading to memory with fread or mmap()ing) using decompress, I get Z_DATA_ERROR. Is it because gzip file has some kind of headers that uncompress doesn't want?

How can I get around this?

Code:
fp = fopen("file.gz", "r");
buf = mmap(0,len,PROT_READ,MAP_SHARED,fileno(fp),0);
assert(buf);

if(uncompress(out,&outsize,buf,len) == Z_DATA_ERROR) fprintf(stderr,"boh\n");
I read somewhere that header is 8 bytes, so I tried
Code:
uncompress(out,&outsize,buf+8,len-8)
but it didn't make any difference either.

Last edited by rayne; 08-28-2006 at 03:27 PM.
Reply With Quote
Forum Sponsor
  #2  
Old 08-29-2006
Registered User
 

Join Date: Nov 2005
Posts: 15
OK, I figured it out.

zlib function uncompress uses inflateInit(), which accepts zlib format, not gzip. I've changed inflateInit() to inflateInit2() and it worked.

However, for 2nd argument of inflateInit2(), I've tried various numbers but it worked for only 24,30,47. Which means at least 16MB of buffer! How can I get around this now?
Reply With Quote
  #3  
Old 08-30-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 979
That is strange, since it's only supposed to accept values of 8...15. What error do you get when you use other values?
Reply With Quote
  #4  
Old 09-17-2006
Registered User
 

Join Date: May 2006
Posts: 101
mmh,
some time ago i used a library call libfz (?) it supports fzopen() that let you read or write any compressed file without much problems.

just my 2 cents, happy hacking
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0