From: Marius Gavrilescu Date: Sat, 9 Sep 2017 17:04:07 +0000 (+0300) Subject: Update brotli to v0.6.0 X-Git-Tag: 0.002_002~1 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=56bfd9c0a0380461b810f820869768f4e8a7ad4a;p=io-compress-brotli.git Update brotli to v0.6.0 --- diff --git a/Brotli.xs b/Brotli.xs index 5b7d008..2370abb 100644 --- a/Brotli.xs +++ b/Brotli.xs @@ -5,9 +5,8 @@ #include "ppport.h" -#include -#include -#include +#include +#include #define BUFFER_SIZE 1048576 @@ -24,24 +23,20 @@ MODULE = IO::Compress::Brotli PACKAGE = IO::Uncompress::Brotli PROTOTYPES: ENABLE SV* -unbro(buffer) +unbro(buffer, decoded_size) SV* buffer + size_t decoded_size PREINIT: - size_t decoded_size; STRLEN encoded_size; uint8_t *encoded_buffer, *decoded_buffer; CODE: encoded_buffer = (uint8_t*) SvPV(buffer, encoded_size); - if(!BrotliDecompressedSize(encoded_size, encoded_buffer, &decoded_size)){ - croak("Error in BrotliDecompressedSize"); - } - Newx(decoded_buffer, decoded_size+1, uint8_t); - decoded_buffer[decoded_size]=0; + Newx(decoded_buffer, decoded_size, uint8_t); if(!BrotliDecoderDecompress(encoded_size, encoded_buffer, &decoded_size, decoded_buffer)){ croak("Error in BrotliDecoderDecompress"); } RETVAL = newSV(0); - sv_usepvn_flags(RETVAL, decoded_buffer, decoded_size, SV_HAS_TRAILING_NUL); + sv_usepvn(RETVAL, decoded_buffer, decoded_size); OUTPUT: RETVAL @@ -73,8 +68,8 @@ decompress(self, in) next_in = (uint8_t*) SvPV(in, available_in); Newx(buffer, BUFFER_SIZE, uint8_t); RETVAL = newSVpv("", 0); - result = BROTLI_RESULT_NEEDS_MORE_OUTPUT; - while(result == BROTLI_RESULT_NEEDS_MORE_OUTPUT) { + result = BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT; + while(result == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) { next_out = buffer; available_out=BUFFER_SIZE; result = BrotliDecoderDecompressStream( self->decoder, @@ -122,7 +117,7 @@ bro(buffer, quality=BROTLI_DEFAULT_QUALITY, lgwin=BROTLI_DEFAULT_WINDOW) if( quality < BROTLI_MIN_QUALITY || quality > BROTLI_MAX_QUALITY ) { croak("Invalid quality value"); } - if( lgwin < kBrotliMinWindowBits || lgwin > kBrotliMaxWindowBits ) { + if( lgwin < BROTLI_MIN_WINDOW_BITS || lgwin > BROTLI_MAX_WINDOW_BITS ) { croak("Invalid window value"); } decoded_buffer = (uint8_t*) SvPV(buffer, decoded_size); @@ -172,7 +167,7 @@ bool BrotliEncoderSetParameter(self, value) croak("BrotliEncoderSetParameter may not be called directly"); break; case 1: - if( value < kBrotliMinWindowBits || value > kBrotliMaxWindowBits ) { + if( value < BROTLI_MIN_WINDOW_BITS || value > BROTLI_MAX_WINDOW_BITS ) { croak("Invalid window value"); } param = BROTLI_PARAM_LGWIN; diff --git a/Makefile.PL b/Makefile.PL index 72fce34..d04bb68 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -16,7 +16,7 @@ WriteMakefile( 'Time::HiRes' => '0', }, BUILD_REQUIRES => {}, - INC => '-Ibrotli', + INC => '-Ibrotli/include', MYEXTLIB => 'brotli/libbrotli$(LIB_EXT)', clean => { FILES => 'brotli/libbrotli$(LIB_EXT)' }, META_ADD => { diff --git a/brotli b/brotli index 2e0d321..46c1a88 160000 --- a/brotli +++ b/brotli @@ -1 +1 @@ -Subproject commit 2e0d3214c2b6248a486822d2c5267d1c961a29d0 +Subproject commit 46c1a881b41bb638c76247558aa04b1591af3aa7 diff --git a/lib/IO/Uncompress/Brotli.pm b/lib/IO/Uncompress/Brotli.pm index 674f44a..75798a2 100644 --- a/lib/IO/Uncompress/Brotli.pm +++ b/lib/IO/Uncompress/Brotli.pm @@ -26,8 +26,8 @@ IO::Uncompress::Brotli - Read Brotli buffers/streams use IO::Uncompress::Brotli; - # uncompress a buffer - my $decoded = unbro $encoded; + # uncompress a buffer (yielding at most 10MB) + my $decoded = unbro $encoded, 10_000_000; # uncompress a stream my $bro = IO::Uncompress::Brotli->create; @@ -51,13 +51,12 @@ function. =over -=item B(I<$input>) +=item B(I<$input>, I<$maximum_decoded_size>) Takes a whole compressed buffer as input and returns the decompressed -data. This function relies on the BrotliDecompressedSize function. In -other words, it only works if the buffer has a single meta block or -two meta-blocks where the first is uncompressed and the second is -empty. +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. Exported by default. diff --git a/t/01-uncompress.t b/t/01-uncompress.t index fe2fe3a..28907ca 100644 --- a/t/01-uncompress.t +++ b/t/01-uncompress.t @@ -2,21 +2,17 @@ use v5.14; use warnings; -use Test::More tests => 80; +use Test::More tests => 84; use File::Slurp; use IO::Uncompress::Brotli; -my $todo_re = qr/empty\.compressed\.(?:1[7-9]|2)|x\.compressed\.0[12]/; - for my $test () { my ($expected) = $test =~ s/\.compressed.*//r; $expected = read_file $expected; - if($test !~ $todo_re) { - my $decoded = unbro (scalar read_file $test); - is $decoded, $expected, "$test"; - } + my $decoded = unbro ((scalar read_file $test), 1_000_000); + is $decoded, $expected, "$test"; open FH, '<', $test; my $unbro = IO::Uncompress::Brotli->create; diff --git a/t/02-roundtrip.t b/t/02-roundtrip.t index 50cf87f..3f656e1 100644 --- a/t/02-roundtrip.t +++ b/t/02-roundtrip.t @@ -14,7 +14,7 @@ for my $test () { for my $quality (9,11) { my $encoded = bro($source, $quality); - my $decoded = unbro($encoded); + my $decoded = unbro($encoded, 1_000_000); is $decoded, $source, "$test - quality $quality"; }