I have a project I'm working on that takes several files, tars them up, and sends them to a client via HTTP. Right now, I create the files, use Archive::Tar to write the tar file to a temporary file (created using IO::File->new_tmpfile()), and then print the temporary file to the browser. That works. I really don't have much of a problem with it, but what I'd really like to do is cut out the middle man tar file and just have the tarfile written directly to STDOUT.

First off, I don't even know if that will work, not really understanding how Archive::Tar itself works. When I try to pass \*STDOUT to Archive::Tar->create_archive() (which takes the name of a file or a reference to filehandle/glob, according to the documentation), I get:

Can't call method "gzwrite" without a package or object reference at / +usr/local/lib/perl5/site_perl/5.6.0/Archive/Tar.pm line 521.
Line 521 in Archive::Tar is:
$file->gzwrite ("\0" x 1024)
And that filehandle is the result of (from Archive::Tar):
$fh = Compress::Zlib::gzdopen_ ($fh, $mode, 0)
The thing is, nothing seems weird. The filehandle should be opened on the fileno for STDOUT and things should progress along smoothly, with all the data being written to STDOUT (in my case, the browser). Is there something in the web server or Zlib which prevents all this from taking place or can anyone think of a better way to do what I'm doing? I'm really at a loss as to wear to begin working towards a solution.

Thanks.


In reply to Tar File To Web Browser by Hrunting

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.