in reply to Tar File To Web Browser

In my Activeperl docs for perl 5.6.0, Archive::Tar says this:

write('file.tar',$compressed)
Will write the in-memory archive to disk. If no filename is given, returns the entire formatted archive as a string, which should be useful if you'd like to stuff the archive into a socket or a pipe to gzip or something. If the second argument is true, the module will try to write the file compressed.

So simply use the multistage set of commands like it says in the docs with a slight change:

use Archive::Tar; $tar = Archive::Tar->new(); $tar->read("origin.tar.gz",1); # you don't seem to want this line thou +gh $tar->add_files("file/foo.c", "file/bar.c"); $tar->add_data("file/baz.c","This is the file contents"); # $tar->write("files.tar"); print STDOUT $tar->write(); # make sure http headers are already print +ed before running this line
Note: I have not tested this but if the docs are correct this should work without mucking around with references to STDOUT. If it still doesn't work it is probably a problem with your copy of the module.

Replies are listed 'Best First'.
Re: Re: Tar File To Web Browser
by Hrunting (Pilgrim) on Dec 10, 2000 at 23:38 UTC
    The problem with this is that unless you pass a file or filehandle to write(), it doesn't actually return tarfile data (at least that's what I'm seeing in Archive::Tar's code) is that the actual data isn't returned, just the formatted listings. The actual routine to write the tar file is only called if you pass a reference to a filehandle or a filename. When I try passing in a reference to STDOUT, I get the same error as before (makes sense, they call the same internal routines).