]> iEval git - io-compress-brotli.git/blame_incremental - Brotli.xs
Remove unuser var total_out
[io-compress-brotli.git] / Brotli.xs
... / ...
CommitLineData
1#define PERL_NO_GET_CONTEXT
2#include "EXTERN.h"
3#include "perl.h"
4#include "XSUB.h"
5
6#include "ppport.h"
7
8#include <dec/decode.h>
9#include <common/dictionary.h>
10
11#define BUFFER_SIZE 1048576
12static uint8_t buffer[BUFFER_SIZE]; /* It's almost 2016, is anyone still using ithreads? */
13
14MODULE = IO::Compress::Brotli PACKAGE = IO::Uncompress::Brotli
15PROTOTYPES: ENABLE
16
17SV* unbro(buffer)
18 SV* buffer
19 PREINIT:
20 size_t decoded_size;
21 STRLEN encoded_size;
22 uint8_t *encoded_buffer, *decoded_buffer;
23 CODE:
24 encoded_buffer = (uint8_t*) SvPV(buffer, encoded_size);
25 if(!BrotliDecompressedSize(encoded_size, encoded_buffer, &decoded_size)){
26 croak("Error in BrotliDecompressedSize");
27 }
28 Newx(decoded_buffer, decoded_size+1, uint8_t);
29 decoded_buffer[decoded_size]=0;
30 if(!BrotliDecoderDecompress(encoded_size, encoded_buffer, &decoded_size, decoded_buffer)){
31 croak("Error in BrotliDecoderDecompress");
32 }
33 RETVAL = newSV(0);
34 sv_usepvn_flags(RETVAL, decoded_buffer, decoded_size, SV_HAS_TRAILING_NUL);
35 OUTPUT:
36 RETVAL
37
38SV* BrotliDecoderCreateInstance()
39 CODE:
40 RETVAL = newSViv((IV)BrotliDecoderCreateInstance(NULL, NULL, NULL));
41 OUTPUT:
42 RETVAL
43
44void BrotliDecoderDestroyInstance(state)
45 SV* state
46 CODE:
47 BrotliDecoderDestroyInstance((BrotliDecoderState*)SvIV(state));
48
49SV* BrotliDecoderDecompressStream(state, in)
50 SV* state
51 SV* in
52 PREINIT:
53 uint8_t *next_in, *next_out;
54 size_t available_in, available_out;
55 BrotliDecoderResult result;
56 CODE:
57 next_in = (uint8_t*) SvPV(in, available_in);
58 RETVAL = newSVpv("", 0);
59 result = BROTLI_RESULT_NEEDS_MORE_OUTPUT;
60 while(result == BROTLI_RESULT_NEEDS_MORE_OUTPUT) {
61 next_out = buffer;
62 available_out=BUFFER_SIZE;
63 result = BrotliDecoderDecompressStream( (BrotliDecoderState*) SvIV(state),
64 &available_in,
65 (const uint8_t**) &next_in,
66 &available_out,
67 &next_out,
68 NULL );
69 if(!result){
70 croak("Error in BrotliDecoderDecompressStream");
71 }
72 sv_catpvn(RETVAL, (const char*)buffer, BUFFER_SIZE-available_out);
73 }
74 OUTPUT:
75 RETVAL
76
77void BrotliDecoderSetCustomDictionary(state, dict)
78 SV* state
79 SV* dict
80 PREINIT:
81 size_t size;
82 uint8_t *data;
83 CODE:
84 data = SvPV(dict, size);
85 BrotliDecoderSetCustomDictionary((BrotliDecoderState*) SvIV(state), size, data);
This page took 0.023197 seconds and 4 git commands to generate.