Gz-use - int err stream.next_in =(Bytef)source stream.avail_in =(uInt)sourceLen Check for source> 64K on 16-bit machine

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
[Contributed by Fekri Kassem] Hey Professor, I started working on my assignment #2 for the web search engine class so I tried to use zlib to uncompress the gz files in memory following the instructions you have in the additional resources for assignment #2 but that doesn't seem to work. After working on it for awhile, I figured out that the uncompress utility function provided by the zlib library doesn't extract gz format. It extract only zlib compressed format. zlib provides a set of gz IO function that could be used instead. I did download the source code of zlib library and did a bit of modification to the uncompress function and it works here is the function to unzip gz format files. I am going to use this function to extract the gz files. int myuncompress(Bytef * dest, uLongf * destLen, const Bytef *source, uLong sourceLen) { z_stream stream;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int err; stream.next_in = (Bytef*)source; stream.avail_in = (uInt)sourceLen; /* Check for source > 64K on 16-bit machine: */ if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; stream.next_out = dest; stream.avail_out = (uInt)*destLen; if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; stream.zalloc = (alloc_func)0; stream.zfree = (free_func)0; // My Modifications: commented out the following line and replaced it with the one after. // err = inflateInit(&stream); err = inflateInit2(&stream, 31); if (err != Z_OK) return err; err = inflate(&stream, Z_FINISH); if (err != Z_STREAM_END) { inflateEnd(&stream); if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) return Z_DATA_ERROR; return err; } *destLen = stream.total_out; err = inflateEnd(&stream); return err; } Thank you, Fekri...
View Full Document

This note was uploaded on 03/07/2010 for the course CS 6913 taught by Professor Torsensuel during the Spring '10 term at NYU Poly.

Ask a homework question - tutors are online