From 799b2a343f40ccc586481aa7b269da5f0abf513f Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Tue, 11 Jun 2019 15:39:25 +0300 Subject: [PATCH] unbro should not require maximum buffer size (RT #129480) --- Brotli.xs | 2 +- lib/IO/Uncompress/Brotli.pm | 20 ++++++++++++++++++++ t/01-uncompress.t | 7 +++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Brotli.xs b/Brotli.xs index ffbde1e..4e030a7 100644 --- a/Brotli.xs +++ b/Brotli.xs @@ -23,7 +23,7 @@ MODULE = IO::Compress::Brotli PACKAGE = IO::Uncompress::Brotli PROTOTYPES: ENABLE SV* -unbro(buffer, decoded_size) +unbro_given_size(buffer, decoded_size) SV* buffer size_t decoded_size PREINIT: diff --git a/lib/IO/Uncompress/Brotli.pm b/lib/IO/Uncompress/Brotli.pm index 1c6671b..0cc22e2 100644 --- a/lib/IO/Uncompress/Brotli.pm +++ b/lib/IO/Uncompress/Brotli.pm @@ -13,6 +13,21 @@ our $VERSION = '0.004001'; require XSLoader; XSLoader::load('IO::Compress::Brotli', $VERSION); +# 0.004 has unbro with prototype $$ +# 0.004_001 renames it to unbro_given_size, and provides unbro with +# prototype $;$ which calls: +# * unbro_given_size when called with two arguments +# * the OO interface when called with one argument +sub unbro ($;$) { + my ($buffer, $decoded_size) = @_; + if (defined $decoded_size) { + return unbro_given_size($buffer, $decoded_size) + } else { + my $bro = IO::Uncompress::Brotli->create; + return $bro->decompress($buffer); + } +} + 1; __END__ @@ -58,6 +73,11 @@ data. It allocates a buffer of size I<$maximum_decoded_size> to store the decompressed data, if this is not sufficient (or there is another error) this function will croak. +As of version 0.004_001, the I<$maximum_decoded_size> argument is +optional. If not provided, B uses the streaming interface +described in the next section to decompress the buffer in blocks of +one megabyte. The decompressed blocks are concatenated and returned. + Exported by default. =back diff --git a/t/01-uncompress.t b/t/01-uncompress.t index f67c5e4..b8fbc6d 100644 --- a/t/01-uncompress.t +++ b/t/01-uncompress.t @@ -2,7 +2,7 @@ use v5.14; use warnings; -use Test::More tests => 84; +use Test::More tests => 126; use File::Slurper qw/read_binary/; use IO::Uncompress::Brotli; @@ -12,7 +12,10 @@ for my $test () { $expected = read_binary $expected; my $decoded = unbro ((scalar read_binary $test), 1_000_000); - is $decoded, $expected, "$test"; + is $decoded, $expected, "$test (two-argument unbro)"; + + $decoded = unbro scalar read_binary $test; + is $decoded, $expected, "$test (one-argument unbro)"; open FH, '<', $test; binmode FH; -- 2.39.2