Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Uncompress Gzip File From WWW::Mechanize

by Anonymous Monk
on Apr 10, 2009 at 00:08 UTC ( #756727=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a gzipped csv file that that was downloaded using WWW::Mechanzie, it can be retrieved by doing:
my $gzipped_csv_file = $mech->content;
How can I unzip the $gzipped_csv_file and store it in $gunzipped without writing to disk?
I don't care about any buffering because it's not a large file.
my $gzipped_csv_file = $mech->content; # uncompress gzip here # store uncompressed file in $gunzipped here my @file = split "\n", $gunzipped;

Comment on Uncompress Gzip File From WWW::Mechanize
Select or Download Code
Re: Uncompress Gzip File From WWW::Mechanize
by jasonk (Parson) on Apr 10, 2009 at 00:29 UTC

    Compress::Zlib makes it easy to do in-memory decompression:

    use Compress::Zlib qw( uncompress ); my $data = uncompress( $mech->content ) or die "Error decompressing content" my @file = split( "\n", $data );

    www.jasonkohles.com
    We're not surrounded, we're in a target-rich environment!
Re: Uncompress Gzip File From WWW::Mechanize
by CoVAX (Beadle) on Feb 09, 2015 at 01:49 UTC

    Presumably you specified (via default_header()) the request header, 'Accept-Encoding' => 'gzip, deflate' beforehand, so you can do this:

    my $gunzipped = $mech->content( 'decoded_by_headers' => 1 );

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://756727]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2015-05-05 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    In my home, the TV remote control is ...









    Results (112 votes), past polls