]> iEval git - io-compress-brotli.git/blame_incremental - lib/IO/Uncompress/Brotli.pm
Update use of deprecated brotli decoder APIs
[io-compress-brotli.git] / lib / IO / Uncompress / Brotli.pm
... / ...
CommitLineData
1package IO::Uncompress::Brotli;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7
8our @EXPORT = qw/unbro/;
9our @EXPORT_OK = @EXPORT;
10
11our $VERSION = '0.001001';
12
13require XSLoader;
14XSLoader::load('IO::Compress::Brotli', $VERSION);
15
16sub create {
17 my ($class) = @_;
18 my $state = BrotliDecoderCreateInstance();
19 bless \$state, $class
20}
21
22sub DESTROY {
23 my ($self) = @_;
24 BrotliDecoderDestroyInstance($$self)
25}
26
27sub decompress {
28 my ($self, $data) = @_;
29 BrotliDecoderDecompressStream($$self, $data)
30}
31
32# Untested, probably not working
33sub set_dictionary {
34 my ($self, $dict) = @_;
35 BrotliSetCustomDictionary($$self, $dict)
36}
37
381;
39__END__
40
41=encoding utf-8
42
43=head1 NAME
44
45IO::Uncompress::Brotli - Read Brotli buffers/streams
46
47=head1 SYNOPSIS
48
49 use IO::Uncompress::Brotli;
50
51 # uncompress a buffer
52 my $decoded = unbro $encoded;
53
54 # uncompress a stream
55 my $bro = IO::Uncompress::Brotli->create;
56 while(have_input()) {
57 my $block = get_input_block();
58 my $decoded_block = $bro->decompress($block);
59 handle_output_block($decoded_block);
60 }
61
62=head1 DESCRIPTION
63
64IO::Uncompress::Brotli is a module that decompresses Brotli buffers
65and streams. Despite its name, it is not a subclass of
66L<IO::Uncompress::Base> and does not implement its interface. This
67will be rectified in a future release.
68
69=head2 One-shot interface
70
71If you have the whole buffer in a Perl scalar use the B<unbro>
72function.
73
74=over
75
76=item B<unbro>(I<$input>)
77
78Takes a whole compressed buffer as input and returns the decompressed
79data. This function relies on the BrotliDecompressedSize function. In
80other words, it only works if the buffer has a single meta block or
81two meta-blocks where the first is uncompressed and the second is
82empty.
83
84Exported by default.
85
86=back
87
88=head2 Streaming interface
89
90If you want to process the data in blocks use the object oriented
91interface. The available methods are:
92
93=over
94
95=item IO::Uncompress::Brotli->B<create>
96
97Returns a IO::Uncompress::Brotli instance. Please note that a single
98instance cannot be used to decompress multiple streams.
99
100=item $bro->B<decompress>(I<$block>)
101
102Takes the a block of compressed data and returns a block of
103uncompressed data. Dies on error.
104
105=back
106
107=head1 SEE ALSO
108
109Brotli Compressed Data Format Internet-Draft:
110L<https://www.ietf.org/id/draft-alakuijala-brotli-08.txt>
111
112Brotli source code: L<https://github.com/google/brotli/>
113
114=head1 AUTHOR
115
116Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
117
118=head1 COPYRIGHT AND LICENSE
119
120Copyright (C) 2015 by Marius Gavrilescu
121
122This library is free software; you can redistribute it and/or modify
123it under the same terms as Perl itself, either Perl version 5.20.2 or,
124at your option, any later version of Perl 5 you may have available.
125
126
127=cut
This page took 0.018765 seconds and 4 git commands to generate.