22#[ cfg( feature = "experimental" ) ]
33use std:: cmp:: min;
44#[ cfg( feature = "experimental" ) ]
5- use std:: io:: { SeekFrom , Seek } ;
5+ use std:: io:: { SeekFrom , Seek , Write } ;
66use std:: io:: { self , BufRead , BufReader , Read } ;
77#[ cfg( feature = "experimental" ) ]
88use std:: mem:: size_of;
@@ -106,7 +106,7 @@ impl<'a, R: Read + Seek> Decoder<'a, BufReader<R>> {
106106
107107 /// Attempt to read a skippable frame and write its content to `dest`.
108108 /// If it cannot read a skippable frame, the reader will be back to its starting position.
109- pub fn read_skippable_frame ( & mut self , dest : & mut [ u8 ] ) -> io:: Result < ( usize , MagicVariant ) > {
109+ pub fn read_skippable_frame < W : Write > ( & mut self , dest : & mut W ) -> io:: Result < ( usize , MagicVariant ) > {
110110 let magic_buffer = self . reader . peek_4bytes ( ) ?;
111111 let op = self . reader . operation ( ) ;
112112 if !op. is_skippable_frame ( & magic_buffer) {
@@ -121,12 +121,8 @@ impl<'a, R: Read + Seek> Decoder<'a, BufReader<R>> {
121121 self . reader . reader_mut ( ) . read_exact ( & mut buffer) ?;
122122 let content_size = u32:: from_le_bytes ( buffer) as usize ;
123123
124- if content_size > dest. len ( ) {
125- return Err ( io:: Error :: new ( io:: ErrorKind :: Other , "Destination buffer is too small" ) ) ;
126- }
127-
128124 if content_size > 0 {
129- self . reader . reader_mut ( ) . read_exact ( & mut dest[ ..content_size ] ) ?;
125+ std :: io :: copy ( & mut self . reader . reader_mut ( ) . take ( content_size as u64 ) , dest) ?;
130126 }
131127
132128 let magic_variant = magic_number - MAGIC_SKIPPABLE_START ;
0 commit comments