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