@@ -59,6 +59,9 @@ impl<R: Read,
59
59
pub fn get_ref ( & self ) -> & R {
60
60
& self . 0 . get_ref ( ) . 0
61
61
}
62
+ pub fn into_inner ( self ) -> R {
63
+ self . 0 . into_inner ( ) . 0
64
+ }
62
65
}
63
66
64
67
#[ cfg( feature="std" ) ]
@@ -93,13 +96,16 @@ impl<R: Read> CompressorReader<R> {
93
96
94
97
pub fn with_params ( r : R , buffer_size : usize , params : & BrotliEncoderParams ) -> Self {
95
98
let mut reader = Self :: new ( r, buffer_size, params. quality as u32 , params. lgwin as u32 ) ;
96
- ( reader. 0 ) . 0 . state . params = params. clone ( ) ;
99
+ ( reader. 0 ) . 0 . state . 0 . params = params. clone ( ) ;
97
100
reader
98
101
}
99
102
100
103
pub fn get_ref ( & self ) -> & R {
101
104
self . 0 . get_ref ( )
102
105
}
106
+ pub fn into_inner ( self ) -> R {
107
+ self . 0 . into_inner ( )
108
+ }
103
109
}
104
110
105
111
@@ -123,7 +129,14 @@ pub struct CompressorReaderCustomIo<ErrType,
123
129
input : R ,
124
130
input_eof : bool ,
125
131
error_if_invalid_data : Option < ErrType > ,
126
- state : BrotliEncoderStateStruct < Alloc > ,
132
+ state : StateWrapper < Alloc > ,
133
+ }
134
+ struct StateWrapper < Alloc : BrotliAlloc > ( BrotliEncoderStateStruct < Alloc > ) ;
135
+
136
+ impl < Alloc : BrotliAlloc > Drop for StateWrapper < Alloc > {
137
+ fn drop ( & mut self ) {
138
+ BrotliEncoderDestroyInstance ( & mut self . 0 ) ;
139
+ }
127
140
}
128
141
129
142
impl < ErrType ,
@@ -145,13 +158,13 @@ CompressorReaderCustomIo<ErrType, R, BufferType, Alloc>
145
158
input_len : 0 ,
146
159
input_eof : false ,
147
160
input : r,
148
- state : BrotliEncoderCreateInstance ( alloc) ,
161
+ state : StateWrapper ( BrotliEncoderCreateInstance ( alloc) ) ,
149
162
error_if_invalid_data : Some ( invalid_data_error_type) ,
150
163
} ;
151
- BrotliEncoderSetParameter ( & mut ret. state ,
164
+ BrotliEncoderSetParameter ( & mut ret. state . 0 ,
152
165
BrotliEncoderParameter :: BROTLI_PARAM_QUALITY ,
153
166
q as ( u32 ) ) ;
154
- BrotliEncoderSetParameter ( & mut ret. state ,
167
+ BrotliEncoderSetParameter ( & mut ret. state . 0 ,
155
168
BrotliEncoderParameter :: BROTLI_PARAM_LGWIN ,
156
169
lgwin as ( u32 ) ) ;
157
170
@@ -169,21 +182,26 @@ CompressorReaderCustomIo<ErrType, R, BufferType, Alloc>
169
182
self . input_offset = 0 ;
170
183
}
171
184
}
172
-
185
+ pub fn into_inner ( self ) -> R {
186
+ match self {
187
+ CompressorReaderCustomIo {
188
+ input_buffer : _ib,
189
+ total_out : _to,
190
+ input_offset : _io,
191
+ input_len : _len,
192
+ input,
193
+ input_eof : _ieof,
194
+ error_if_invalid_data : _eiid,
195
+ state : _state,
196
+ } => {
197
+ input
198
+ }
199
+ }
200
+ }
173
201
pub fn get_ref ( & self ) -> & R {
174
202
& self . input
175
203
}
176
204
}
177
-
178
- impl < ErrType ,
179
- R : CustomRead < ErrType > ,
180
- BufferType : SliceWrapperMut < u8 > ,
181
- Alloc : BrotliAlloc > Drop for
182
- CompressorReaderCustomIo < ErrType , R , BufferType , Alloc > {
183
- fn drop ( & mut self ) {
184
- BrotliEncoderDestroyInstance ( & mut self . state ) ;
185
- }
186
- }
187
205
impl < ErrType ,
188
206
R : CustomRead < ErrType > ,
189
207
BufferType : SliceWrapperMut < u8 > ,
@@ -215,7 +233,7 @@ CompressorReaderCustomIo<ErrType, R, BufferType, Alloc> {
215
233
op = BrotliEncoderOperation :: BROTLI_OPERATION_PROCESS ;
216
234
}
217
235
let ret = BrotliEncoderCompressStream (
218
- & mut self . state ,
236
+ & mut self . state . 0 ,
219
237
op,
220
238
& mut avail_in,
221
239
& self . input_buffer . slice_mut ( ) [ ..] ,
@@ -231,7 +249,7 @@ CompressorReaderCustomIo<ErrType, R, BufferType, Alloc> {
231
249
if ret <= 0 {
232
250
return Err ( self . error_if_invalid_data . take ( ) . unwrap ( ) ) ;
233
251
}
234
- let fin = BrotliEncoderIsFinished ( & mut self . state ) ;
252
+ let fin = BrotliEncoderIsFinished ( & mut self . state . 0 ) ;
235
253
if fin != 0 {
236
254
break ;
237
255
}
@@ -241,152 +259,3 @@ CompressorReaderCustomIo<ErrType, R, BufferType, Alloc> {
241
259
}
242
260
243
261
244
-
245
- /*
246
-
247
- /////////////////BOGUS////////////////////////////////////
248
- pub struct SimpleReader<R: Read,
249
- BufferType: SliceWrapperMut<u8>>
250
- {
251
- input_buffer: BufferType,
252
- total_out: Option<usize>,
253
- input_offset: usize,
254
- input_len: usize,
255
- input_eof: bool,
256
- input: R,
257
- error_if_invalid_data: Option<io::Error>,
258
- read_error: Option<io::Error>,
259
- state: BrotliEncoderStateStruct<HeapAlloc<u8>, HeapAlloc<u16>, HeapAlloc<u32>, HeapAlloc<i32>, HeapAlloc<Command>>,
260
- }
261
-
262
- impl<R: Read,
263
- BufferType : SliceWrapperMut<u8>>
264
- SimpleReader<R, BufferType>
265
- {
266
-
267
- pub fn new(r: R, buffer : BufferType,
268
- q: u32,
269
- lgwin: u32) -> Option<Self> {
270
- let mut ret = SimpleReader{
271
- input_buffer : buffer,
272
- total_out : Some(0),
273
- input_offset : 0,
274
- input_len : 0,
275
- input_eof : false,
276
- input: r,
277
- state : BrotliEncoderCreateInstance(HeapAlloc{default_value:0},
278
- HeapAlloc{default_value:0},
279
- HeapAlloc{default_value:0},
280
- HeapAlloc{default_value:0},
281
- HeapAlloc{default_value:Command::default()}),
282
- error_if_invalid_data : Some(Error::new(ErrorKind::InvalidData,
283
- "Invalid Data")),
284
- read_error : None,
285
- };
286
- BrotliEncoderSetParameter(&mut ret.state,
287
- BrotliEncoderParameter::BROTLI_PARAM_QUALITY,
288
- q as (u32));
289
- BrotliEncoderSetParameter(&mut ret.state,
290
- BrotliEncoderParameter::BROTLI_PARAM_LGWIN,
291
- lgwin as (u32));
292
-
293
- Some(ret)
294
- }
295
- pub fn copy_to_front(&mut self) {
296
- let avail_in = self.input_len - self.input_offset;
297
- if self.input_offset == self.input_buffer.slice_mut().len() {
298
- self.input_offset = 0;
299
- self.input_len = 0;
300
- } else if self.input_offset + 256 > self.input_buffer.slice_mut().len() && avail_in < self.input_offset {
301
- let (first, second) = self.input_buffer.slice_mut().split_at_mut(self.input_offset);
302
- first[0..avail_in].clone_from_slice(&second[0..avail_in]);
303
- self.input_len -= self.input_offset;
304
- self.input_offset = 0;
305
- }
306
- }
307
-
308
- pub fn get_ref(&self) -> &R {
309
- &self.input
310
- }
311
- }
312
-
313
- impl<R: Read,
314
- BufferType : SliceWrapperMut<u8>> Drop for
315
- SimpleReader<R, BufferType> {
316
- fn drop(&mut self) {
317
- BrotliEncoderDestroyInstance(&mut self.state);
318
- }
319
- }
320
- impl<R: Read,
321
- BufferType : SliceWrapperMut<u8>> Read for
322
- SimpleReader<R, BufferType> {
323
- fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
324
- let mut nop_callback = |_data:&[interface::Command<input_pair::InputReferenceMut>]|();
325
- let mut output_offset : usize = 0;
326
- let mut avail_out = buf.len() - output_offset;
327
- let mut avail_in = self.input_len - self.input_offset;
328
- let mut needs_input = false;
329
- while avail_out == buf.len() && (!needs_input || !self.input_eof) {
330
- if self.input_len < self.input_buffer.slice_mut().len() && !self.input_eof {
331
- match self.input.read(&mut self.input_buffer.slice_mut()[self.input_len..]) {
332
- Err(e) => {
333
- self.read_error = Some(e);
334
- self.input_eof = true;
335
- },
336
- Ok(size) => if size == 0 {
337
- self.input_eof = true;
338
- }else {
339
- needs_input = false;
340
- self.input_len += size;
341
- avail_in = self.input_len - self.input_offset;
342
- },
343
- }
344
- }
345
- let op : BrotliEncoderOperation;
346
- if avail_in == 0 {
347
- op = BrotliEncoderOperation::BROTLI_OPERATION_FINISH;
348
- } else {
349
- op = BrotliEncoderOperation::BROTLI_OPERATION_PROCESS;
350
- }
351
- let ret = BrotliEncoderCompressStream(
352
- &mut self.state,
353
- &mut HeapAlloc{default_value:0},
354
- &mut HeapAlloc{default_value:0.0},
355
- &mut HeapAlloc{default_value:Mem256f::default()},
356
- &mut HeapAlloc{default_value:HistogramLiteral::default()},
357
- &mut HeapAlloc{default_value:HistogramCommand::default()},
358
- &mut HeapAlloc{default_value:HistogramDistance::default()},
359
- &mut HeapAlloc{default_value:HistogramPair::default()},
360
- &mut HeapAlloc{default_value:ContextType::default()},
361
- &mut HeapAlloc{default_value:HuffmanTree::default()},
362
- &mut HeapAlloc{default_value:ZopfliNode::default()},
363
- op,
364
- &mut avail_in,
365
- &self.input_buffer.slice_mut()[..],
366
- &mut self.input_offset,
367
- &mut avail_out,
368
- buf,
369
- &mut output_offset,
370
- &mut self.total_out,
371
- &mut nop_callback);
372
- if avail_in == 0 {
373
- match self.read_error.take() {
374
- Some(err) => return Err(err),
375
- None => {
376
- needs_input = true;
377
- self.copy_to_front();
378
- },
379
- }
380
- }
381
- if ret <= 0 {
382
- return Err(self.error_if_invalid_data.take().unwrap());
383
- }
384
- let fin = BrotliEncoderIsFinished(&mut self.state);
385
- if fin != 0 {
386
- break;
387
- }
388
- }
389
- Ok(output_offset)
390
- }
391
- }
392
- */
0 commit comments