Bump version and update Changes
[io-compress-brotli.git] / lib / IO / Compress / Brotli.pm
CommitLineData
f9995f31
MG
1package IO::Compress::Brotli;
2
3use 5.014000;
4use strict;
5use warnings;
55f6d186 6use parent qw/Exporter/;
f9995f31 7
f108816b
MG
8use Carp qw/croak/;
9
09cf7186
QR
10use IO::Uncompress::Brotli;
11
09cf7186
QR
12our @EXPORT = qw/bro/;
13our @EXPORT_OK = @EXPORT;
14
406e6fed 15our $VERSION = '0.004_002';
f9995f31 16
09cf7186
QR
17my %BROTLI_ENCODER_MODE = ( generic => 0, text => 1, font => 2 );
18sub mode {
19 my ($self, $mode) = @_;
20
f108816b 21 croak 'Invalid encoder mode'
09cf7186
QR
22 unless $BROTLI_ENCODER_MODE{$mode};
23
d3f7abb9 24 _mode($$self, $mode)
09cf7186
QR
25}
26
09cf7186 27
f9995f31
MG
281;
29__END__
30
31=encoding utf-8
32
33=head1 NAME
34
795dca12 35IO::Compress::Brotli - Write Brotli buffers/streams
f9995f31
MG
36
37=head1 SYNOPSIS
38
39 use IO::Compress::Brotli;
40
09cf7186
QR
41 # compress a buffer
42 my $encoded = bro $encoded;
43
44 # compress a stream
45 my $bro = IO::Compress::Brotli->create;
46 while(have_input()) {
47 my $block = get_input_block();
48 my $encoded_block = $bro->compress($block);
49 handle_output_block($encoded_block);
50 }
51 # Need to finish the steam
52 handle_output_block($bro->finish());
53
f9995f31
MG
54=head1 DESCRIPTION
55
09cf7186
QR
56IO::Compress::Brotli is a module that compressed Brotli buffers
57and streams. Despite its name, it is not a subclass of
58L<IO::Compress::Base> and does not implement its interface. This
59will be rectified in a future release.
60
61=head2 One-shot interface
62
63If you have the whole buffer in a Perl scalar use the B<bro>
64function.
65
66=over
67
593b81c0 68=item B<bro>(I<$input>, I<$quality>, I<$window>)
09cf7186
QR
69
70Takes a whole uncompressed buffer as input and returns the compressed
593b81c0
MZ
71data using the supplied quality and window parameters. If quality and
72window parameters are not supplied, default values are used (as
73described under the object-oriented interface).
09cf7186
QR
74
75Exported by default.
76
77=back
78
79=head2 Streaming interface
80
81If you want to process the data in blocks use the object oriented
82interface. The available methods are:
83
84=over
85
86=item IO::Compress::Brotli->B<create>
87
88Returns a IO::Compress::Brotli instance. Please note that a single
89instance cannot be used to decompress multiple streams.
90
91=item $bro->B<window>(I<$window>)
92
93Sets the window parameter on the brotli encoder.
94Defaults to BROTLI_DEFAULT_WINDOW (22).
95
96=item $bro->B<quality>(I<$quality>)
97
98Sets the quality paremeter on the brotli encoder.
99Defaults to BROTLI_DEFAULT_QUALITY (11).
100
101=item $bro->B<mode>(I<$mode>)
102
103Sets the brotli encoder mode, which can be any of "generic",
104"text" or "font". Defaults to "generic".
105
106=item $bro->B<compress>(I<$block>)
107
108Takes the a block of uncompressed data and returns a block of
109compressed data. Dies on error.
110
111=item $bro->B<flush>()
112
113Flushes any pending output from the encoder.
114
115=item $bro->B<finish>()
116
117Tells the encoder to start the finish operation, and flushes
118any remaining compressed output.
119
120Once finish is called, the encoder cannot be used to compress
121any more content.
122
123B<NOTE>: Calling finish is B<required>, or the output might
124remain unflushed, and the be missing termination marks.
125
126=back
127
128=head1 SEE ALSO
129
130Brotli Compressed Data Format Internet-Draft:
131L<https://www.ietf.org/id/draft-alakuijala-brotli-08.txt>
132
133Brotli source code: L<https://github.com/google/brotli/>
f9995f31
MG
134
135=head1 AUTHOR
136
137Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
138
4c5aa4f8
MG
139The encoder bindings, modernisation of the decoder bindings and a
140clean up of the overall project were contributed by:
141
142=over
143
144=item Quim Rovira, E<lt>quim@rovira.catE<gt>
145
146=item Ævar Arnfjörð Bjarmason, E<lt>avarab@gmail.comE<gt>
147
148=item Marcell Szathmári
149
150=item Mattia Barbon, E<lt>mattia@barbon.orgE<gt>
151
152=back
153
f9995f31
MG
154=head1 COPYRIGHT AND LICENSE
155
b4be88fe 156Copyright (C) 2015-2018 by Marius Gavrilescu
f9995f31
MG
157
158This library is free software; you can redistribute it and/or modify
159it under the same terms as Perl itself, either Perl version 5.20.2 or,
160at your option, any later version of Perl 5 you may have available.
161
162
163=cut
This page took 0.020411 seconds and 4 git commands to generate.