Rework reading from device and clean up.
This commit is contained in:
15
src/io.rs
Normal file
15
src/io.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use std::io::{self, Seek, SeekFrom};
|
||||
|
||||
/// Get length of data stream.
|
||||
/// Physical length of data stream in bytes
|
||||
/// (multiple of sector_size, rather than actual).
|
||||
///
|
||||
/// This will attempt to return the stream to its current read position.
|
||||
pub fn get_stream_length<S: Seek>(stream: &mut S) -> io::Result<u64> {
|
||||
let pos = stream.stream_position()?;
|
||||
let len = stream.seek(SeekFrom::End(0));
|
||||
|
||||
stream.seek(SeekFrom::Start(pos))?;
|
||||
|
||||
len
|
||||
}
|
||||
Reference in New Issue
Block a user