19 August 2006
This post may be outdated due to it was written on 2006. The links may be broken. The code may be not working anymore. Leave comments if needed.
Thank God, Thank IO::Scalar.

u know we can transfer a filehandle to $c->res->body. and IO::Scalar is making my life easy.

just a snippet code, have fun.
sub test : Local {
my ( $self, $c ) = @_;

use Archive::Zip qw(:ERROR_CODES :CONSTANTS);

my $zip = Archive::Zip->new();

$c->res->content_type('application/octet-stream');
$c->res->headers->header( 'Content-Disposition' => "attachment; filename=\"fayland.zip" );

use IO::Scalar;
my $data;
my $fh = new IO::Scalar \$data;

$zip->addFile('E:/Fayland/index.html') or die $!;
$zip->writeToFileHandle($fh);

$c->res->body($data);
}
IO::Scalar 能将一个 $scalar 作为 filehandle IO 来对待。在 Catalyst 里将是特别有用的。


blog comments powered by Disqus