Reading file as vec of byte

Good evening,
i have a file in .rdfc format. The file contains a vector of bytes in little endian format.
i would to read this file and calculate the crc of it.
I tried to use this way:

use std::fs::File;
use std::io::Read;

let mut vec_areas = Vec::new();
let file_open = File::open("myfile.rdfc");
let mut match_names = match file_open {
                    Ok(file) => file,
                    Err(_) => return (),

let vec_total = match_names.read_to_end(& mut vec_areas);
match vec_total{ 
                    Ok(file) => println!("{}", file),
                    Err(_)=> return (),

if i print my file it returns me a size of this one.

I don't really understand what's the question here, but vec_areas is holding the file content bytes if you are looking for it.

if it holds my file when i print i should obtain my vector of byte, not the size

You are printing vec_total, not vec_areas. vec_total will contain the size, and the read bytes are put into vec_areas.

You are printing vec_total, the return value of read_to_end, which contains the length if no error occurs. The one holding the bytes is vec_areas, you can check it with println!("{:?}", vec_areas);.

There's an easy way to read a whole file:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.