From 1e52b32f6bd55dfdb4a85d574904d0d7d26a4e99 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Thu, 17 Mar 2005 17:52:53 +0000 Subject: [PATCH] Updated archive builder, to avoid compressing things which probably don't benefit from it This was SVN commit r2001. --- source/tools/archbuilder/archbuild.pl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/source/tools/archbuilder/archbuild.pl b/source/tools/archbuilder/archbuild.pl index ba348c098e..db22dc915c 100644 --- a/source/tools/archbuilder/archbuild.pl +++ b/source/tools/archbuilder/archbuild.pl @@ -356,10 +356,23 @@ sub create_archive { my $zip = new Archive::Zip; for my $file (@$files) { + if ($file->[1]->archive) { + $zip->addMember($file->[1]->location) or die "Error adding zipped file $file->[0] to zip"; + } else { - $zip->addFile($file->[1]->location, $file->[0]) or die "Error adding file $file->[0] to zip"; + + my $member = Archive::Zip::Member->newFromFile($file->[1]->location) or die "Error adding file $file->[0] to zip"; + $member->fileName($file->[0]); + + if (should_compress($file->[1]->location)) { + $member->desiredCompressionMethod(Archive::Zip::COMPRESSION_DEFLATED); + } else { + $member->desiredCompressionMethod(Archive::Zip::COMPRESSION_STORED); + } + + $zip->addMember($member); } } @@ -379,4 +392,11 @@ sub get_opt { } } return $default; +} + +sub should_compress { + my ($filename) = @_; + return 0 if $filename =~ /\.(ogg|png)$/i; # don't compress things that are already compressed + return 0 if (stat $filename)[7] < 8192; # don't compress small files + return 1; } \ No newline at end of file