uncompress of zlib


 
Thread Tools Search this Thread
Top Forums Programming uncompress of zlib
# 1  
Old 08-28-2006
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 07:27 PM..
# 2  
Old 08-29-2006
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?
# 3  
Old 08-30-2006
That is strange, since it's only supposed to accept values of 8...15. What error do you get when you use other values?
# 4  
Old 09-17-2006
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Problem compiling glib using static zlib

Hello I have been trying to compile glib 2.28 with needs Zlib. During the compilation process I received these messages Then giving a look at the configure of Zlib, there was an option to static link it and I obviously used it. So I think I can solve it by compiling a shared zlib, or by... (4 Replies)
Discussion started by: colt
4 Replies

2. Shell Programming and Scripting

zlib.h in custom path

I am trying to configure gpac. I get the error as follows. # ./configure error: zlib not found on system or in local libs I have installed zlib on custom path /usr/local/myapps. I know the above error occurs when devel package or .h file is not present. Its present on the server. # ll... (7 Replies)
Discussion started by: anilcliff
7 Replies

3. BSD

Installing zlib

Is there a port or shorthand way of installing the zlib library on FreeBSD? I currently use the following: wget http://zlib.net/zlib-1.2.5.tar.gz tar zxf zlib*.gz cd zlib*\. ./configure --libdir=/usr/lib --includedir=/usr/include make install clean This is somewhat contrived code and for a... (4 Replies)
Discussion started by: figaro
4 Replies

4. Solaris

Cannot uncompress the tar.gz

I've downloaded the tomcat from http://archive.apache.org/dist/jakarta/tomcat-5/v5.0.30/bin/ at window 2000 and then ftp to Solaris 5.9 in binary mode. gunzip -c jakarta-tomcat-5.0.30.tar.gz | tar -xvf - tar: directory checksum error if try this one, gzip -d jakarta-tomcat-5.0.30.tar.gz... (2 Replies)
Discussion started by: sbox
2 Replies

5. Shell Programming and Scripting

Help with uncompress...Urgent

Hi, I am restoring the database backup using compress utility(/usr/bin/compress) which takes around 1 hour.For restoration i use uncompress utility(/usr/bin/uncompress) which is taking nearly 6-7 hours.Can someone let me know how to reduce this time.I have pasted below the line from script... (2 Replies)
Discussion started by: santtarius
2 Replies

6. UNIX for Advanced & Expert Users

how to compress .zlib file

Hi all, I wanted to know how to compress a .zlib file.. an working on unix so pls suggest accordingly. the file is pretty big(500 mb) also i would like to know any weblinks where i can get more info on various compressions commands in unix i have tried zip,compress commands but i have not... (1 Reply)
Discussion started by: wrapster
1 Replies

7. Programming

problem about using zlib to uncompress gzip in memory

I wrote a function which for uncompressing data for gzip or deflate format using zlib,see followed code; source param is pointed to the compressed data,len param is the size of compressed data, dest param is for returning the address which pointed to the uncompressed data;the last gzip param tell... (0 Replies)
Discussion started by: iwishfine
0 Replies

8. UNIX for Advanced & Expert Users

uncompress command

on my suse linux, there is no compress and uncompress command. however, a program need these command to be installed properly. my question is how i can install these command and where to find them, thanks! (6 Replies)
Discussion started by: fredao
6 Replies

9. UNIX for Advanced & Expert Users

uncompress

Hi All, is it possible to uncompress on another directory ? At the moment I have my file to uncompress on /u07 that has 5GB free. When uncompressed it would be more then 6G , I want to send uncompressed file on another directory where I have more free space. is it possible ? How ? Many thanks... (3 Replies)
Discussion started by: big123456
3 Replies

10. UNIX for Dummies Questions & Answers

Uncompress... me!!!!!! :)

Dear friends, i'm trying to uncompress an "...... tar.z" file. I'd readen that using the "uncompress" command it could be made but............... God! I can't!!!!! I tried a lot of times using the Terminal but the uncompress command doesn't obeys!!! :):) . Please i need to know how to... (3 Replies)
Discussion started by: gussiglo21
3 Replies
Login or Register to Ask a Question