#file-read #eof #io #behaves

bufferedreader

A BufferedReader that behaves like the underlying File.read

1 stable release

1.0.0 Jan 18, 2021

#4 in #eof

MIT license

6KB
91 lines

BufferedReader

Description

This crate provides a BufferedReader that operates like the underlying File.read. That means:

  • If EOF then it returns the current number of bytes that could be read before EOF
  • If no EOF will be reached then the buffer shall be full

Example

Here is an example usage

use std::io::Result;

fn main() -> Result<()>
{
    let fle = File::open("./my_big_file")?;
    //The BufferedReader takes ownership so don't try to use the fle after this call
    let mut reader = BufferedReader::new(fle);
    let mut buf: [u8; 4] = [0; 4]; //Read 4 by 4 bytes
    let mut res = reader.read(&mut buf)?;

    while res > 0
    {
        println!("Read {} byte(s)", res);
        res = reader.read(&mut buf)?;
    }
    return Ok(());
}

No runtime deps