2
2
#[ cfg( feature = "experimental" ) ]
3
3
use std:: cmp:: min;
4
4
#[ cfg( feature = "experimental" ) ]
5
- use std:: io:: { SeekFrom , Seek } ;
5
+ use std:: io:: { SeekFrom , Seek , Write } ;
6
6
use std:: io:: { self , BufRead , BufReader , Read } ;
7
7
#[ cfg( feature = "experimental" ) ]
8
8
use std:: mem:: size_of;
@@ -106,7 +106,7 @@ impl<'a, R: Read + Seek> Decoder<'a, BufReader<R>> {
106
106
107
107
/// Attempt to read a skippable frame and write its content to `dest`.
108
108
/// 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 ) > {
110
110
let magic_buffer = self . reader . peek_4bytes ( ) ?;
111
111
let op = self . reader . operation ( ) ;
112
112
if !op. is_skippable_frame ( & magic_buffer) {
@@ -121,12 +121,8 @@ impl<'a, R: Read + Seek> Decoder<'a, BufReader<R>> {
121
121
self . reader . reader_mut ( ) . read_exact ( & mut buffer) ?;
122
122
let content_size = u32:: from_le_bytes ( buffer) as usize ;
123
123
124
- if content_size > dest. len ( ) {
125
- return Err ( io:: Error :: new ( io:: ErrorKind :: Other , "Destination buffer is too small" ) ) ;
126
- }
127
-
128
124
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) ?;
130
126
}
131
127
132
128
let magic_variant = magic_number - MAGIC_SKIPPABLE_START ;
0 commit comments