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