[][src]Function dia_files::read

pub fn read<R>(src: R, limit: Option<usize>) -> Result<Vec<u8>> where
    R: Read

Reads bytes from a source

Notes

  • If data to be read exceeds limit, an error is returned. If you don't care about exceeding data, you can use Read::take().

Examples

use std::{
    fs::File,
    io,
    path::PathBuf,
};

fn test() -> io::Result<()> {
    let f = file!();
    let file_size = PathBuf::from(f).metadata()?.len();

    assert_eq!(
        dia_files::read(File::open(f)?, None)?.len(),
        dia_files::read(File::open(f)?, Some(file_size as usize))?.len(),
    );

    dia_files::read(File::open(f)?, Some(0)).unwrap_err();

    Ok(())
}

test().unwrap();