Forum Moderators: coopster & phranque

Message Too Old, No Replies

Decompressing gzipped files

Compressed with Compress::Zlib::memGzip

         

Birdman

5:47 pm on May 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

I'm hoping someone can shed some light on how to decompress the files that I compressed and saved to disk. I used Compress::Zlib::memGzip to compress them but cannot seem to open them and decompress to their normal state.

I've tried every possible way I can come up with, including gzopen() and Compress::Zlib::memGunzip :(

Here is the relevant code used to compress and save to disk:


require Compress::Zlib;
my $new_content = Compress::Zlib::memGzip($content);
if (defined $new_content) {
$response->content($new_content);
$response->content_length(length $new_content);
$response->content_encoding("gzip");
open LOG, ">>search/$docid" or die "Can't append-open $docid: $!";
select(LOG);
$¦ = 1; # Make LOG unbuffered
print LOG $content;

Thanks for any help!

Birdman

moltar

6:01 pm on May 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does the file come out corrupted? Do you use windows? If so, you have to tell windows that your files are binary. Try this:


...
open LOG, ">>search/$docid" or die "Can't append-open $docid: $!";
[b][url=http://www.rocketaware.com/perl/perlfunc/binmode.htm]binmode[/url](LOG);[/b]
select(LOG);
...

Birdman

6:16 pm on May 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks moltar, that was fast!

Yes on both of your questions. So you are saying I did it wrong from the beginning and I'll need to delete the files and start again, using binmode() before the save to disk?

When I first wrote the script that saves the compressed files, I tested decompressing using Compress::Zlib::memGunzip and it worked fine while it was in-memory. I never even considered that things would change after it was saved and reopened.

Birdman

moltar

6:20 pm on May 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you saved you gzip'ed file without binmode, then I guess you'll need to save it again.

I just quickly looked over the docs for the Compress::Zlib::memGzip and I've noticed that even in their examples they use binmode(). Take a look at the docs.

Birdman

6:26 pm on May 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks alot for the help! I may still be in business. I got one to open and it looks good, just need to gunzip it and see if it's readable.

I'll let you know what happens. You got me on the right track now!

Birdman