]>
iEval git - io-compress-brotli.git/blob - lib/IO/Compress/Brotli.pm
1 package IO
::Compress
::Brotli
;
7 use IO
::Uncompress
::Brotli
;
9 use parent qw
/Exporter/;
11 our @EXPORT = qw
/bro/;
12 our @EXPORT_OK = @EXPORT;
14 our $VERSION = '0.001001';
16 my %BROTLI_ENCODER_MODE = ( generic
=> 0, text
=> 1, font
=> 2 );
18 my ($self, $mode) = @_;
20 die "Invalid encoder mode"
21 unless $BROTLI_ENCODER_MODE{$mode};
34 IO::Compress::Brotli - Write Brotli buffers/streams
38 use IO::Compress::Brotli;
41 my $encoded = bro $encoded;
44 my $bro = IO::Compress::Brotli->create;
46 my $block = get_input_block();
47 my $encoded_block = $bro->compress($block);
48 handle_output_block($encoded_block);
50 # Need to finish the steam
51 handle_output_block($bro->finish());
55 IO::Compress::Brotli is a module that compressed Brotli buffers
56 and streams. Despite its name, it is not a subclass of
57 L<IO::Compress::Base> and does not implement its interface. This
58 will be rectified in a future release.
60 =head2 One-shot interface
62 If you have the whole buffer in a Perl scalar use the B<bro>
67 =item B<bro>(I<$input>)
69 Takes a whole uncompressed buffer as input and returns the compressed
76 =head2 Streaming interface
78 If you want to process the data in blocks use the object oriented
79 interface. The available methods are:
83 =item IO::Compress::Brotli->B<create>
85 Returns a IO::Compress::Brotli instance. Please note that a single
86 instance cannot be used to decompress multiple streams.
88 =item $bro->B<window>(I<$window>)
90 Sets the window parameter on the brotli encoder.
91 Defaults to BROTLI_DEFAULT_WINDOW (22).
93 =item $bro->B<quality>(I<$quality>)
95 Sets the quality paremeter on the brotli encoder.
96 Defaults to BROTLI_DEFAULT_QUALITY (11).
98 =item $bro->B<mode>(I<$mode>)
100 Sets the brotli encoder mode, which can be any of "generic",
101 "text" or "font". Defaults to "generic".
103 =item $bro->B<compress>(I<$block>)
105 Takes the a block of uncompressed data and returns a block of
106 compressed data. Dies on error.
108 =item $bro->B<flush>()
110 Flushes any pending output from the encoder.
112 =item $bro->B<finish>()
114 Tells the encoder to start the finish operation, and flushes
115 any remaining compressed output.
117 Once finish is called, the encoder cannot be used to compress
120 B<NOTE>: Calling finish is B<required>, or the output might
121 remain unflushed, and the be missing termination marks.
127 Brotli Compressed Data Format Internet-Draft:
128 L<https://www.ietf.org/id/draft-alakuijala-brotli-08.txt>
130 Brotli source code: L<https://github.com/google/brotli/>
134 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
136 =head1 COPYRIGHT AND LICENSE
138 Copyright (C) 2015 by Marius Gavrilescu
140 This library is free software; you can redistribute it and/or modify
141 it under the same terms as Perl itself, either Perl version 5.20.2 or,
142 at your option, any later version of Perl 5 you may have available.
This page took 0.050922 seconds and 4 git commands to generate.