1 /* Copyright 2013 Google Inc. All Rights Reserved.
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
7 /* Functions for streaming input and output. */
13 #include "./streams.h"
15 #if defined(__cplusplus) || defined(c_plusplus)
19 int BrotliMemInputFunction(void* data
, uint8_t* buf
, size_t count
) {
20 BrotliMemInput
* input
= (BrotliMemInput
*)data
;
21 if (input
->pos
> input
->length
) {
24 if (input
->pos
+ count
> input
->length
) {
25 count
= input
->length
- input
->pos
;
27 memcpy(buf
, input
->buffer
+ input
->pos
, count
);
32 BrotliInput
BrotliInitMemInput(const uint8_t* buffer
, size_t length
,
33 BrotliMemInput
* mem_input
) {
35 mem_input
->buffer
= buffer
;
36 mem_input
->length
= length
;
38 input
.cb_
= &BrotliMemInputFunction
;
39 input
.data_
= mem_input
;
43 int BrotliMemOutputFunction(void* data
, const uint8_t* buf
, size_t count
) {
44 BrotliMemOutput
* output
= (BrotliMemOutput
*)data
;
45 size_t limit
= output
->length
- output
->pos
;
49 memcpy(output
->buffer
+ output
->pos
, buf
, count
);
54 BrotliOutput
BrotliInitMemOutput(uint8_t* buffer
, size_t length
,
55 BrotliMemOutput
* mem_output
) {
57 mem_output
->buffer
= buffer
;
58 mem_output
->length
= length
;
60 output
.cb_
= &BrotliMemOutputFunction
;
61 output
.data_
= mem_output
;
65 int BrotliFileInputFunction(void* data
, uint8_t* buf
, size_t count
) {
66 return (int)fread(buf
, 1, count
, (FILE*)data
);
69 BrotliInput
BrotliFileInput(FILE* f
) {
71 in
.cb_
= BrotliFileInputFunction
;
76 int BrotliFileOutputFunction(void* data
, const uint8_t* buf
, size_t count
) {
77 return (int)fwrite(buf
, 1, count
, (FILE*)data
);
80 BrotliOutput
BrotliFileOutput(FILE* f
) {
82 out
.cb_
= BrotliFileOutputFunction
;
87 int BrotliNullOutputFunction(void* data
, const uint8_t* buf
, size_t count
) {
93 BrotliOutput
BrotliNullOutput(void) {
95 out
.cb_
= BrotliNullOutputFunction
;
100 #if defined(__cplusplus) || defined(c_plusplus)
This page took 0.023228 seconds and 4 git commands to generate.