]>
iEval git - io-compress-brotli.git/blob - lib/IO/Compress/Brotli.pm
694a04b301dc48a66aa205f045d1816d1a0afb1d
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};
27 BROTLI_OPERATION_PROCESS
=> 0,
28 BROTLI_OPERATION_FLUSH
=> 1,
29 BROTLI_OPERATION_FINISH
=> 2
32 my ($self, $data) = @_;
33 $self->_compress($data, BROTLI_OPERATION_PROCESS
)
38 $self->_compress('', BROTLI_OPERATION_FLUSH
)
43 $self->_compress('', BROTLI_OPERATION_FINISH
)
53 IO::Compress::Brotli - Write Brotli buffers/streams
57 use IO::Compress::Brotli;
60 my $encoded = bro $encoded;
63 my $bro = IO::Compress::Brotli->create;
65 my $block = get_input_block();
66 my $encoded_block = $bro->compress($block);
67 handle_output_block($encoded_block);
69 # Need to finish the steam
70 handle_output_block($bro->finish());
74 IO::Compress::Brotli is a module that compressed Brotli buffers
75 and streams. Despite its name, it is not a subclass of
76 L<IO::Compress::Base> and does not implement its interface. This
77 will be rectified in a future release.
79 =head2 One-shot interface
81 If you have the whole buffer in a Perl scalar use the B<bro>
86 =item B<bro>(I<$input>)
88 Takes a whole uncompressed buffer as input and returns the compressed
95 =head2 Streaming interface
97 If you want to process the data in blocks use the object oriented
98 interface. The available methods are:
102 =item IO::Compress::Brotli->B<create>
104 Returns a IO::Compress::Brotli instance. Please note that a single
105 instance cannot be used to decompress multiple streams.
107 =item $bro->B<window>(I<$window>)
109 Sets the window parameter on the brotli encoder.
110 Defaults to BROTLI_DEFAULT_WINDOW (22).
112 =item $bro->B<quality>(I<$quality>)
114 Sets the quality paremeter on the brotli encoder.
115 Defaults to BROTLI_DEFAULT_QUALITY (11).
117 =item $bro->B<mode>(I<$mode>)
119 Sets the brotli encoder mode, which can be any of "generic",
120 "text" or "font". Defaults to "generic".
122 =item $bro->B<compress>(I<$block>)
124 Takes the a block of uncompressed data and returns a block of
125 compressed data. Dies on error.
127 =item $bro->B<flush>()
129 Flushes any pending output from the encoder.
131 =item $bro->B<finish>()
133 Tells the encoder to start the finish operation, and flushes
134 any remaining compressed output.
136 Once finish is called, the encoder cannot be used to compress
139 B<NOTE>: Calling finish is B<required>, or the output might
140 remain unflushed, and the be missing termination marks.
146 Brotli Compressed Data Format Internet-Draft:
147 L<https://www.ietf.org/id/draft-alakuijala-brotli-08.txt>
149 Brotli source code: L<https://github.com/google/brotli/>
153 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
155 =head1 COPYRIGHT AND LICENSE
157 Copyright (C) 2015 by Marius Gavrilescu
159 This library is free software; you can redistribute it and/or modify
160 it under the same terms as Perl itself, either Perl version 5.20.2 or,
161 at your option, any later version of Perl 5 you may have available.
This page took 0.050825 seconds and 3 git commands to generate.