ganeshPerlStarter has asked for the wisdom of the Perl Monks concerning the following question:

Hi Friends I've a perl script to download (using LWP::UserAgent) a winzip file containing only one txt file, extract certain data (using IO::Uncompress::Unzip) from this file & delete downloaded zip file after processing. Problem with IO::Uncompress::Unzip is that it takes only the file (on disk) as input. Whereas, the HTML::Response object returned by LWP::UserAgent::get() method contains the downloaded content in string (in memory). So, I want to eliminate the writing of zipfile to filesystem completely & consume the in-memory compressed buffer for processing. Can I please know, do we've a perl module that can take winzip compressed in-memory data (as scalar or scalar-reference) and provide the uncompressed data as stream or a memory buffer? Thanks
  • Comment on Uncompressing winzip downloaded in memory

Replies are listed 'Best First'.
Re: Uncompressing winzip downloaded in memory
by Athanasius (Archbishop) on Feb 04, 2015 at 04:09 UTC

    Hello ganeshPerlStarter,

    The IO::Uncompress::Unzip::unzip function also accepts a reference to a string for the input:

    #! perl use strict; use warnings; use IO::Uncompress::Unzip qw(unzip $UnzipError) ; my $file = 'data.zip'; open(my $fh, '<', $file) or die "Cannot open file '$file' for reading: $!"; binmode $fh; my $input; { local $/ = undef; $input = <$fh>; } close $fh or die "Cannot close file '$file': $!"; my $output; my $status = unzip \$input => \$output or die "Unzip failed: $UnzipError\n"; print "Status: $status\n"; print "Unzipped text:\n\n>>>$output<<<\n";

    I created a text file named “data.txt” and zipped it to “data.zip” using 7-Zip. The above script reads the zipped file data into the scalar $input, then correctly unzips it when passed a reference to the scalar (string) — \$input — as the input parameter.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Hi, Yes this helps. Thanks for quick resolution Best Regards
Re: Uncompressing winzip downloaded in memory
by Anonymous Monk on Feb 04, 2015 at 03:59 UTC