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