I am trying to send a compressed tarball from a perl cgi script. Everything is working fine, except for the fact that the tarball is only being sent after it has been compressed and created. In other words it is not 'streaming' the data live which is quite problematic because the data is quite large.
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=download.tar.\n\n";
print `tar zc $path/$file`
I开发者_开发百科 have also tried doing tar zcf - $path/$file
which writes to stdout and it does the same thing.
As Geo pointed, you are waiting for tar
to finish. Reading from pipe should also output data in parallel with its creation:
open my $pipe_fh, '-|', "tar zc $path/$file" or die;
while(<$pipe_fh>) {
print;
}
Well, in the case of backticks, you are practically waiting for the process to finish, and then you are sending it's output. I would suggest something from the IPC::Open
family. IPC::Open3 could do the trick.
精彩评论