bufferedreader

Crates.iobufferedreader
lib.rsbufferedreader
version1.0.0
sourcesrc
created_at2021-01-18 19:17:05.03494
updated_at2021-01-18 19:17:05.03494
descriptionA BufferedReader that behaves like the underlying File.read.
homepage
repositoryhttps://gitlab.com/Yuri6037/BufferedReader
max_upload_size
id343634
size6,797
(Yuri6037)

documentation

README

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(());
}
Commit count: 5

cargo fmt