Skip to content

Instantly share code, notes, and snippets.

@bimmerlabs bimmerlabs/
Last active Jan 11, 2018

What would you like to do?
A Mojolicious::Lite forZip file streaming with Mojo::Asset::Memory
#!/usr/bin/env perl
use Mojolicious::Lite;
use Archive::Zip::SimpleZip qw($SimpleZipError);
get '/#file' => sub {
my $c = shift;
# read a file from disk
my $file1 =
path => '/path/to/' . $c->param('file')
# generate one on the fly
my @file2 = (
my $file2 = Mojo::Asset::Memory->new;
foreach my $line (@file2) {
my $zipfile;
my $zip = Archive::Zip::SimpleZip->new(\$zipfile)
or die "Cannot create zip file: $SimpleZipError\n" ;
$zip->addString( $file1->slurp, Name => $c->param('file') );
$zip->addString( $file2->slurp, Name => 'test.txt' );
# stream zip file with Mojo::Asset::Memory
'attachment; filename=' . $c->param('file') . '.zip;');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.