[cgiapp] very huge file modes

Jason Purdy jason at journalistic.com
Mon Jul 13 08:27:21 EDT 2009


Paul,

You may want to check out CAP::Stream, which will handle file handling:

http://search.cpan.org/~purdy/CGI-Application-Plugin-Stream-2.10/lib/CGI/Application/Plugin/Stream.pm

It would reduce your runmode to this:

sub run_mode {
   my $cgi_application = shift; # that's a long variable name ;)
   my $very_huge_file = '/path/to/file';
   if ( $cgi_application->stream_file( $very_huge_file ) ) {
     return;
   } else {
     die "problem";
   }
}

- Jason

Paul Miller wrote:
> I'm trying to do something like this... it seems to work, but I'm
> wondering if it'll backfire down the line.
> 
> sub run_mode {
>     my $cgi_application = shift;
>     my $cgi = $cgi_application->query;
> 
>     open my $very_huge_file, "<", $filename or die $!cgiapp at lists.openlib.org
>     print $cgi->header("application/octet-stream");
>     my $buf;
>     while( read $very_huge_file, $buf, 2048 ) {
>         print $buf;
>     }
>     exit 0;
> }
> 


More information about the cgiapp mailing list