That simple?

Matt Lawrence matt.lawrence at virgin.net
Tue Apr 24 16:29:52 BST 2012


It might be a good idea to binmode that handle, just in case there's 
CRLF or unicode translations on by default. I think just changing the 
mode in open() to '<:raw' will do the trick.

The only other problem I can see is that errors in read() won't be 
handled particularly nicely, afaict this will just deliver truncated 
output, which the client may not realise is incomplete until they feed 
it to unzip. Read failures should be very rare, but I think adding a 
Content-Length header should make it behave nicely.

Also consider using autodie to get more informative log messages if 
read, print or close fail.

Matt

On 24/04/12 13:40, gvim wrote:
> I'm trying to serve a large zip file (678MB) in 3MB chunks to which I 
> will add password protection. I found the PHP code listed below but 
> wanted to stick with Perl. My first, potentially naive, solution is 
> listed below but I want to make sure I'm not overlooking some 
> essential checking and edge cases.
>
> givm
>
> ************ Perl ********************
>
> use CGI::Simple::Standard qw( header );
>
> open my $INFILE, '<', 'dld.zip' or die "Can't open file: $!\n";
> print header(-type => 'application/zip', -attachment => 'dld.zip');
> while (read $INFILE, my $buffer, 3145728) {
>   print $buffer;
> }
> close $INFILE;



More information about the london.pm mailing list