@@ -63,12 +63,27 @@ impl<'a> DecompressionStruct<'a> {
6363 }
6464
6565 pub fn is_encodings_empty ( & self ) -> bool {
66- self . encoding_info
67- . last ( )
66+ match self . encoding_info . split_last ( ) {
67+ Some ( ( last, rest) ) if rest. is_empty ( ) => {
68+ last. encodings ( ) . is_empty ( )
69+ }
70+ _ => false ,
71+ }
72+ }
73+
74+ /*
75+ pub fn is_encodings_empty(&self) -> bool {
76+ let mut iter = self.encoding_info.iter().rev();
77+ if iter
78+ .next()
6879 .unwrap()
6980 .encodings()
7081 .is_empty()
71- }
82+ {
83+ return iter.next().is_none();
84+ }
85+ false
86+ }*/
7287
7388 pub fn extra ( & self ) -> & [ u8 ] {
7489 self . extra . as_ref ( ) . unwrap ( ) . as_ref ( )
@@ -100,39 +115,38 @@ impl<'a> DecompressionStruct<'a> {
100115
101116 pub fn try_decompress_main_plus_extra (
102117 & mut self ,
103- ) -> Result < BytesMut , MultiDecompressError > {
104- let to_copy = self . main . len ( ) + self . extra ( ) . len ( ) ;
105- let mut buf = self . writer . get_mut ( ) ;
106- buf. reserve ( to_copy) ;
107- // copy main and extra to buf
108- buf. put ( self . main . as_ref ( ) ) ;
109- buf. put ( self . extra . as_ref ( ) . unwrap ( ) . as_ref ( ) ) ;
110- let combined = buf. split ( ) ;
111- decompress_multi ( & combined, & mut self . writer , & self . encoding_info )
112- }
113-
114- pub fn try_decompress_main_plus_extra_new (
115- & mut self ,
116118 ) -> Result < BytesMut , MultiDecompressError > {
117119 let last_encoding = self . pop_last_encoding ( ) ;
118120 let mut chained = Cursor :: new ( self . main . as_ref ( ) )
119121 . chain ( Cursor :: new ( self . extra . as_ref ( ) . unwrap ( ) . as_ref ( ) ) ) ;
120- let _ = decompress_single ( chained, & mut self . writer , & last_encoding)
121- . map_err ( |e| {
122- MultiDecompressError :: new ( MultiDecompressErrorReason :: Corrupt , e)
123- } ) ?;
122+ dbg ! ( & chained) ;
123+ let _ =
124+ decompress_single ( & mut chained, & mut self . writer , & last_encoding)
125+ . map_err ( |e| {
126+ MultiDecompressError :: new (
127+ MultiDecompressErrorReason :: Corrupt ,
128+ e,
129+ )
130+ } ) ?;
131+ let ( main, extra) = chained. get_ref ( ) ;
132+ dbg ! ( main. position( ) ) ;
133+ dbg ! ( extra. position( ) ) ;
124134
125135 let output = self . writer . get_mut ( ) . split ( ) ;
136+ //dbg!(&output);
137+ //dbg!(&self.encoding_info);
138+ //dbg!(&self.writer);
126139 if self . is_encodings_empty ( ) {
140+ dbg ! ( "empty" ) ;
127141 Ok ( output)
128142 } else {
129- let _ = decompress_multi (
143+ let result = decompress_multi (
130144 & output,
131145 & mut self . writer ,
132146 & self . encoding_info ,
133147 ) ?;
134148 self . push_last_encoding ( last_encoding) ;
135- Ok ( self . writer . get_mut ( ) . split ( ) )
149+ Ok ( result )
136150 }
137151 }
138152}
@@ -174,7 +188,7 @@ mod tests {
174188 ) ;
175189 assert_eq ! (
176190 decompression_struct. last_encoding( ) ,
177- & ContentEncoding :: Identity
191+ & ContentEncoding :: Zstd
178192 ) ;
179193 }
180194
@@ -190,7 +204,7 @@ mod tests {
190204 ) ;
191205 assert_eq ! (
192206 decompression_struct. last_encoding( ) ,
193- & ContentEncoding :: Identity
207+ & ContentEncoding :: Zstd
194208 ) ;
195209 }
196210
@@ -231,9 +245,9 @@ mod tests {
231245 vec![
232246 ContentEncoding :: Brotli ,
233247 ContentEncoding :: Deflate ,
248+ ContentEncoding :: Identity ,
234249 ContentEncoding :: Gzip ,
235250 ContentEncoding :: Zstd ,
236- ContentEncoding :: Identity ,
237251 ContentEncoding :: Brotli ,
238252 ] ,
239253 ) ] ;
@@ -255,19 +269,19 @@ mod tests {
255269 let to_verify = vec ! [
256270 EncodingInfo :: new( 0 , vec![ ContentEncoding :: Brotli ] ) ,
257271 EncodingInfo :: new( 1 , vec![ ContentEncoding :: Deflate ] ) ,
258- EncodingInfo :: new( 2 , vec![ ContentEncoding :: Gzip ] ) ,
259- EncodingInfo :: new( 3 , vec![ ContentEncoding :: Zstd ] ) ,
272+ EncodingInfo :: new( 2 , vec![ ContentEncoding :: Identity ] ) ,
273+ EncodingInfo :: new( 3 , vec![ ContentEncoding :: Gzip ] ) ,
260274 EncodingInfo :: new(
261275 4 ,
262- vec![ ContentEncoding :: Identity , ContentEncoding :: Brotli ] ,
276+ vec![ ContentEncoding :: Zstd , ContentEncoding :: Brotli ] ,
263277 ) ,
264278 ] ;
265279
266280 assert_eq ! ( decompression_struct. encoding_info, to_verify) ;
267281 }
268282
269283 #[ test]
270- fn test_dstruct_is_encodings_empty_true ( ) {
284+ fn test_dstruct_is_encodings_empty_true_single_value ( ) {
271285 let mut encoding_info = vec ! [ EncodingInfo :: new( 0 , vec![ ] ) ] ;
272286 let mut buf = BytesMut :: new ( ) ;
273287 let decompression_struct = DecompressionStruct :: new (
@@ -280,7 +294,7 @@ mod tests {
280294 }
281295
282296 #[ test]
283- fn test_dstruct_is_encodings_empty_false ( ) {
297+ fn test_dstruct_is_encodings_empty_false_single_value ( ) {
284298 let mut encoding_info =
285299 vec ! [ EncodingInfo :: new( 0 , vec![ ContentEncoding :: Gzip ] ) ] ;
286300 let mut buf = BytesMut :: new ( ) ;
@@ -292,4 +306,20 @@ mod tests {
292306 ) ;
293307 assert ! ( !decompression_struct. is_encodings_empty( ) ) ;
294308 }
309+
310+ #[ test]
311+ fn test_dstruct_is_encodings_empty_false_last_encoding_empty ( ) {
312+ let mut encoding_info = vec ! [
313+ EncodingInfo :: new( 0 , vec![ ContentEncoding :: Gzip ] ) ,
314+ EncodingInfo :: new( 1 , vec![ ] ) ,
315+ ] ;
316+ let mut buf = BytesMut :: new ( ) ;
317+ let decompression_struct = DecompressionStruct :: new (
318+ & [ ] ,
319+ None ,
320+ & mut encoding_info,
321+ ( & mut buf) . writer ( ) ,
322+ ) ;
323+ assert ! ( !decompression_struct. is_encodings_empty( ) ) ;
324+ }
295325}
0 commit comments