FU::Util: Add brotli_compress() and use it for FU output compression
Seems to compresses and perform better than libdeflate at level 6, so certainly worth using.
This commit is contained in:
parent
bc33fe53f0
commit
6159b33950
5 changed files with 99 additions and 14 deletions
35
t/compress.t
35
t/compress.t
|
|
@ -1,18 +1,34 @@
|
|||
use v5.36;
|
||||
use Test::More;
|
||||
use FU::Util qw/gzip_lib gzip_compress/;
|
||||
use FU::Util qw/gzip_lib gzip_compress brotli_compress/;
|
||||
|
||||
like gzip_lib, qr/^(|libdeflate|zlib-ng|zlib)$/, gzip_lib;
|
||||
|
||||
plan skip_all => 'No suitable gzip library found' if !gzip_lib;
|
||||
plan skip_all => 'Compress::Zlib not found' if !eval { require Compress::Zlib };
|
||||
my $incompressible;
|
||||
|
||||
my $incompressible = Compress::Zlib::memGzip(join '', map chr(rand 256), 0..93123);
|
||||
subtest 'gzip_compress', sub {
|
||||
plan skip_all => 'No suitable gzip library found' if !gzip_lib;
|
||||
plan skip_all => 'Compress::Zlib not found' if !eval { require Compress::Zlib };
|
||||
|
||||
for my $str ('', 'Hello world!', 'x'x4096, $incompressible) {
|
||||
is Compress::Zlib::memGunzip(gzip_compress(0, $str)), $str;
|
||||
is Compress::Zlib::memGunzip(gzip_compress(12, $str)), $str;
|
||||
}
|
||||
$incompressible = Compress::Zlib::memGzip(join '', map chr(rand 256), 0..93123);
|
||||
|
||||
for my $str ('', 'Hello world!', 'x'x4096, $incompressible) {
|
||||
is Compress::Zlib::memGunzip(gzip_compress(0, $str)), $str;
|
||||
is Compress::Zlib::memGunzip(gzip_compress(12, $str)), $str;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
subtest 'brotli_compress', sub {
|
||||
plan skip_all => 'libbrotlienc not available'
|
||||
if !eval { brotli_compress 6, '' } && $@ =~ /Unable to load/;
|
||||
|
||||
ok length(brotli_compress 0, '') > 0;
|
||||
ok length(brotli_compress 11, '') > 0;
|
||||
# '0' does not disable compression...
|
||||
ok length(brotli_compress 0, 'Hello world!'x100) < 200;
|
||||
ok length(brotli_compress 11, 'Hello world!'x100) < 100;
|
||||
};
|
||||
|
||||
|
||||
done_testing;
|
||||
|
|
@ -29,6 +45,8 @@ for (0..1000) {
|
|||
local $_ = gzip_lib;
|
||||
$_ = gzip_compress(0, $str);
|
||||
$_ = gzip_compress(12, $str);
|
||||
$_ = brotli_compress(0, $str);
|
||||
$_ = brotli_compress(11, $str);
|
||||
}
|
||||
}
|
||||
diag count_sv;
|
||||
|
|
@ -44,4 +62,5 @@ my $data = <$F>;
|
|||
cmpthese -3, {
|
||||
memGzip => 'Compress::Zlib::memGzip($data)',
|
||||
gzip_compress => 'gzip_compress(6, $data)',
|
||||
brotli_compress => 'brotli_compress(6, $data)',
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue