From 318564ac033c757f01c7a2a4d92e3b18a59bb354 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sun, 6 Jan 2019 09:17:28 +0100 Subject: [PATCH] buffered_read: return empty buffer on eof --- src/backup/archive_index.rs | 2 ++ src/tools.rs | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backup/archive_index.rs b/src/backup/archive_index.rs index 44155081..70b43a2a 100644 --- a/src/backup/archive_index.rs +++ b/src/backup/archive_index.rs @@ -231,6 +231,8 @@ impl <'a> crate::tools::BufferedReader for BufferedArchiveReader<'a> { fn buffered_read(&mut self, offset: u64) -> Result<&[u8], Error> { + if offset == self.archive_size { return Ok(&self.read_buffer[0..0]); } + let buffer_len = self.read_buffer.len(); let index = self.index; diff --git a/src/tools.rs b/src/tools.rs index f9036bb9..6ba62320 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -21,8 +21,9 @@ pub mod timer; /// `buffered_read`. It returns a reference to an internal buffer. The /// purpose of this traid is to avoid unnecessary data copies. pub trait BufferedReader { - /// This functions tries to fill the internal buffers, then returns - /// a reference to the available data. + /// This functions tries to fill the internal buffers, then + /// returns a reference to the available data. It returns an empty + /// buffer if `offset` points to the end of the file. fn buffered_read(&mut self, offset: u64) -> Result<&[u8], Error>; }