File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -184,13 +184,14 @@ impl Num {
184184/// directly in `buf_size`-sized chunks, matching GNU dd's behavior.
185185/// Returns the total number of bytes actually read.
186186fn read_and_discard < R : Read > ( reader : & mut R , n : u64 , buf_size : usize ) -> io:: Result < u64 > {
187- let mut buf = vec ! [ 0u8 ; buf_size] ;
187+ // todo: consider splice()ing to /dev/null on Linux
188+ let mut buf = Vec :: with_capacity ( buf_size) ;
188189 let mut total = 0u64 ;
189190 let mut remaining = n;
190-
191191 while remaining > 0 {
192- let to_read = cmp:: min ( remaining, buf_size as u64 ) as usize ;
193- match reader. read ( & mut buf[ ..to_read] ) {
192+ let to_read = cmp:: min ( remaining, buf_size as u64 ) ;
193+ buf. clear ( ) ;
194+ match reader. by_ref ( ) . take ( to_read) . read_to_end ( & mut buf) {
194195 Ok ( 0 ) => break , // EOF
195196 Ok ( bytes_read) => {
196197 total += bytes_read as u64 ;
You can’t perform that action at this time.
0 commit comments