Add tests for compression, and a CLI tool for manual testing.
[io-compress-brotli.git] / bin / bro-perl
CommitLineData
2786a68d
QR
1#!perl
2#
3
4use warnings;
5use strict;
6use 5.014;
7
8use File::Slurp;
9use Getopt::Long;
10
11use IO::Compress::Brotli;
12use IO::Uncompress::Brotli;
13
14GetOptions(
15 'c|custom-dictionary=s' => \(my $DICTIONARY),
16 'd|decompress' => \(my $DECOMPRESS),
17 'h|help' => \(my $HELP),
18 'i|input=s' => \(my $INPUT),
19 'o|output=s' => \(my $OUTPUT),
20 'q|quality=i' => \(my $QUALITY = 11),
21 'r|repeat=i' => \(my $REPEAT),
22 's|stream=i' => \(my $STREAM),
23 'v|verbose' => \(my $VERBOSE),
24 'w|window=i' => \(my $WINDOW = 22),
25);
26
27if( $HELP ) {
28 say "Usage: $0 [--force] [--quality n] [--decompress] [--input filename] [--output filename]".
29 " [--repeat iters] [--verbose] [--window n] [--custom-dictionary filename] [--stream size]";
30 exit 1;
31}
32
33my ($ifh, $ofh) = (\*STDIN, \*STDOUT);
34
35if( $INPUT ) {
36 open $ifh, "<", $INPUT
37 or die "Cannot open input file $INPUT.\n";
38}
39binmode $ifh;
40
41if( $OUTPUT ) {
42 open $ofh, ">", $OUTPUT
43 or die "Cannot open output file $OUTPUT.\n";
44}
45binmode $ofh;
46
47if( $DECOMPRESS ) {
48 if( $STREAM ) {
49 my $brotli = IO::Uncompress::Brotli->create();
50 while( read $ifh, (my $buf), $STREAM ) {
51 print $ofh $brotli->decompress($buf);
52 }
53 }
54 else {
55 my $encoded = read_file( $ifh );
56 my $decoded = unbro( $encoded );
57 write_file( $ofh, $decoded );
58 }
59}
60else {
61 if( $STREAM ) {
62 my $brotli = IO::Compress::Brotli->create();
63 $brotli->quality( $QUALITY );
64 $brotli->window( $WINDOW );
65 while( read $ifh, (my $buf), $STREAM ) {
66 print $ofh $brotli->compress($buf);
67 }
68 }
69 else {
70 my $decoded = read_file( $ifh );
71 my $encoded = bro( $decoded, $QUALITY, $WINDOW );
72 write_file( $ofh, $encoded );
73 }
74}
75
This page took 0.012779 seconds and 4 git commands to generate.