pub struct FileReader { /* private fields */ }
Expand description
A simple buffered and bounded file reader.
The implementation is much simpler than FileSource
.
FileReader
treats file as a fixed depot of bytes.
Attempt to read beyond the end will result in a NotEnoughBytes
error.
Implementationsยง
Sourceยงimpl FileReader
impl FileReader
pub async fn new(file_id: FileId) -> Result<Self, FileErr>
Sourcepub async fn seek(&mut self, to: SeqPos) -> Result<u64, FileErr>
pub async fn seek(&mut self, to: SeqPos) -> Result<u64, FileErr>
Seek the file stream to a different position. SeqNo is regarded as byte offset. Returns the file offset after sought.
pub fn offset(&self) -> u64
pub fn file_size(&self) -> u64
pub async fn resize(&mut self) -> Result<u64, FileErr>
Trait Implementationsยง
Sourceยงimpl ByteSource for FileReader
impl ByteSource for FileReader
Sourceยงfn request_bytes(&mut self, size: usize) -> Self::Future<'_>
fn request_bytes(&mut self, size: usize) -> Self::Future<'_>
Read N bytes from file. If there is not enough bytes, it will return NotEnoughBytes
error.
If there are enough bytes in the buffer, it yields immediately.
type Future<'a> = Pin<Box<dyn Future<Output = Result<Bytes, FileErr>> + Send + 'a>>
Auto Trait Implementationsยง
impl Freeze for FileReader
impl RefUnwindSafe for FileReader
impl Send for FileReader
impl Sync for FileReader
impl Unpin for FileReader
impl UnwindSafe for FileReader
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more