pub fn read_chunk(reader: &mut Read, len: usize) -> Result<Vec<u8>, Error> {
    let mut result = vec![0u8; len];

    // Number of bytes read so far, used as an index into result.
    let mut i = 0; 
    while i < len {
        // Read from the file.
        let n = match reader.read(&mut result[i..len]) {
            Ok(n) => n,
            Err(e) => return Err(e.into())
        };
        i += n;

        // println!("read {:?} bytes", n);

        // Ok(0) is EOF.
        if n == 0 {
            break;
        }
    }
    // println!("returning {:?} bytes", i);
    // In case the total bytes read is smaller than expected,
    // (EOF or last block in the file).
    result.truncate(i);
    // println!("returning {:?} bytes", result.len());
    Ok(result)
}
// Reads a chunk of up to len bytes. Any return value smaller than
// len indicates EOF has been reached.
Reads a chunk of up to len bytes. Any return value smaller than
len indicates EOF has been reached.
Reads a chunk of up to len bytes . Any return value smaller than len indicates EOF has been reached .
pub fn read_chunk(reader: &mut Read, len: usize) -> Result<Vec<u8>, Error> {
    let mut result = vec![0u8; len];
    // Number of bytes read so far, used as an index into result.
    let mut i = 0; 
    while i < len {
        // Read from the file.
        let n = match reader.read(&mut result[i..len]) {
            Ok(n) => n,
            Err(e) => return Err(e.into())
        };
        i += n;
        // println!("read {:?} bytes", n);
        // Ok(0) is EOF.
        if n == 0 {
            break;
        }
    }
    // println!("returning {:?} bytes", i);
    // In case the total bytes read is smaller than expected,
    // (EOF or last block in the file).
    result.truncate(i);
    // println!("returning {:?} bytes", result.len());
    Ok(result)
}
pub fn read_chunk ( reader : & mut Read , len : usize ) -> Result < Vec < u8 > , Error > { let mut result = vec ! [ 0u8 len ] ; // Number of bytes read so far, used as an index into result. let mut i = 0 ; while i < len { // Read from the file. let n = match reader . read ( & mut result [ i .. len ] ) { Ok ( n ) => n , Err ( e ) => return Err ( e . into ( ) ) } ; i += n ; // println!("read {:?} bytes", n); // Ok(0) is EOF. if n == 0 { break ; } } // println!("returning {:?} bytes", i); // In case the total bytes read is smaller than expected, // (EOF or last block in the file). result . truncate ( i ) ; // println!("returning {:?} bytes", result.len()); Ok ( result ) }
Reads a chunk of up to len bytes.
Reads a chunk of up to len bytes .
reader
&mut Read
len
usize
reader
&mut Read
len
usize