]> iEval git - io-compress-brotli.git/commitdiff
Update brotli to v0.6.0
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 9 Sep 2017 17:04:07 +0000 (20:04 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 9 Sep 2017 17:04:07 +0000 (20:04 +0300)
Brotli.xs
Makefile.PL
brotli
lib/IO/Uncompress/Brotli.pm
t/01-uncompress.t
t/02-roundtrip.t

index 5b7d008594a958e07e8a12f5be841a9655bd52d8..2370abbcef9b2df7dcfa86ded4ec306c2dea17f7 100644 (file)
--- a/Brotli.xs
+++ b/Brotli.xs
@@ -5,9 +5,8 @@
 
 #include "ppport.h"
 
-#include <dec/decode.h>
-#include <enc/encode.h>
-#include <common/dictionary.h>
+#include <brotli/decode.h>
+#include <brotli/encode.h>
 
 #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;
index 72fce34eacd7ac67f26db531fb710abfc94ef2ba..d04bb68598b00d1d070e46dfff9354c3577b66e7 100644 (file)
@@ -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 2e0d3214c2b6248a486822d2c5267d1c961a29d0..46c1a881b41bb638c76247558aa04b1591af3aa7 160000 (submodule)
--- a/brotli
+++ b/brotli
@@ -1 +1 @@
-Subproject commit 2e0d3214c2b6248a486822d2c5267d1c961a29d0
+Subproject commit 46c1a881b41bb638c76247558aa04b1591af3aa7
index 674f44aac5443019d26c02df8e27ece045081fb2..75798a2703ed5a178d3a66b3518813ec8e939caa 100644 (file)
@@ -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<unbro>(I<$input>)
+=item B<unbro>(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.
 
index fe2fe3a665ba47ddcb8afcd82647df79c7ee9e66..28907ca0ffd6618acab8d0ddd70e2b1172372fec 100644 (file)
@@ -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 (<brotli/tests/testdata/*.compressed*>) {
        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;
index 50cf87f02d3aca3257b12fae45c7499371247f66..3f656e18f3b700bb7706fc5984ad58599b5409de 100644 (file)
@@ -14,7 +14,7 @@ for my $test (<brotli/tests/testdata/*.compressed>) {
 
        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";
        }
This page took 0.037172 seconds and 4 git commands to generate.