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;

In reply to Re^2: Using Archive::Tar on tar data already in memory by alpiner2
in thread Using Archive::Tar on tar data already in memory by cengineer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.