in reply to Re: Using Archive::Tar on tar data already in memory
in thread Using Archive::Tar on tar data already in memory
Suppose we were to take this one step further and have this completely in memory without reading in a file at all.
I'm using LWP::Simple and pull down a tar.gz from a cgi that prints the binary data.
$tarInput is a scalar which contains the tar data. Since gzread (or bzread) can't read in
scalars or filehandles created from IO::Scalar, need to use a combination of the above 2 posts.
I pass $tarInput to Compress::Zlib::memGunzip and it returns another scalar with the uncompressed
data. Take that data and create a filehandle with the IO::Scalar module and pass that to
$tar->read. I had been working on finding a solution for this and thought this thread would be appropriate
to post my findings. As always there could be more than one way to do this, this just happens to
work for me.
use Archive::Tar; use LWP::Simple; use IO::Scalar; use Compress::Zlib; use strict; my $device = shift; my $tarInput = get "http://somehost/cgi-bin/getTar.cgi?device=$device" +; my $uncomptar = Compress::Zlib::memGunzip($tarInput); my $sh = new IO::Scalar \$uncomptar; my $tar = Archive::Tar->new; $tar->read($sh); print join "\n", $tar->list_files;
|
|---|