Fix bin/bro-perl
[io-compress-brotli.git] / bin / bro-perl
index 6aac129481f9ac5dcc86ad11caaae5f314777acc..ad35af8b20a7c6307c879b4e57cdedc7a18dc452 100755 (executable)
@@ -1,11 +1,10 @@
 #!perl
-#
 
 use warnings;
 use strict;
 use 5.014;
 
-use bytes;
+use bytes ();
 
 use File::Slurp;
 use Getopt::Long;
@@ -15,7 +14,6 @@ use IO::Compress::Brotli;
 use IO::Uncompress::Brotli;
 
 GetOptions(
-    'c|custom-dictionary=s' => \(my $DICTIONARY),
     'd|decompress'          => \(my $DECOMPRESS),
     'f|force'               => \(my $FORCE),
     'h|help'                => \(my $HELP),
@@ -30,7 +28,7 @@ GetOptions(
 
 if( $HELP ) {
     say "Usage: $0 [--force] [--quality n] [--decompress] [--input filename] [--output filename]".
-        " [--repeat iters] [--verbose] [--window n] [--custom-dictionary filename] [--stream size]";
+        " [--repeat iters] [--verbose] [--window n] [--stream size]";
     exit 1;
 }
 
@@ -54,7 +52,7 @@ for ( 1..$REPEAT ) {
 
     my $ofh;
     if( $OUTPUT ) {
-        die "Output file exists"
+        die "Output file exists\n"
             if( -e $OUTPUT && $REPEAT == 1 && !$FORCE );
         open $ofh, ">", $OUTPUT
             or die "Cannot open output file $OUTPUT.\n";
@@ -63,19 +61,12 @@ for ( 1..$REPEAT ) {
     binmode $ofh;
 
     if( $DECOMPRESS ) {
-        if( $STREAM ) {
-            my $bro = IO::Uncompress::Brotli->create();
-            while( read $ifh, (my $buf), $STREAM ) {
-                $decoded = $bro->decompress($buf);
-                $total_size += bytes::length( $decoded );
-                print $ofh $decoded;
-            }
-        }
-        else {
-            $encoded = read_file( $ifh );
-            $decoded = unbro( $encoded );
+        $STREAM //= 4 * 1024 * 1024;
+        my $bro = IO::Uncompress::Brotli->create();
+        while( read $ifh, (my $buf), $STREAM ) {
+            $decoded = $bro->decompress($buf);
             $total_size += bytes::length( $decoded );
-            write_file( $ofh, $decoded );
+            print $ofh $decoded;
         }
     }
     else {
@@ -85,17 +76,16 @@ for ( 1..$REPEAT ) {
             $bro->window( $WINDOW );
             while( read $ifh, (my $buf), $STREAM ) {
                 $encoded = $bro->compress($buf);
-                $total_size += bytes::length( $encoded );
+                $total_size += bytes::length( $buf );
                 print $ofh $encoded;
             }
             $encoded = $bro->finish();
-            $total_size += bytes::length( $encoded );
             print $ofh $encoded;
         }
         else {
             my $decoded = read_file( $ifh );
             my $encoded = bro( $decoded, $QUALITY, $WINDOW );
-            $total_size += bytes::length( $encoded );
+            $total_size += bytes::length( $decoded );
             write_file( $ofh, $encoded );
         }
     }
This page took 0.011485 seconds and 4 git commands to generate.