How do you read the bytes from the center of a file?

Is there a way (without using external libraries) to read the contents of a file from and only from, let's say, index 123 to index 5432. The purpose for using this is for storing large amounts of information in files, but not wanting to make too many files and to not load it all into Ram. Is there any way to do this?

An example of the theoretical function that I am requesting is:

read_file_contents(&self, start_index: u64, end_index: u64) -> &[u8] { /*code*/ }

You can use File's std::io::Seek implementation to seek to a given index:

file.seek(SeekFrom::Start(start_index))?;
4 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.