From 53c0cb664a2b6b37af68027c5992295be9cddd7d Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Tue, 20 Apr 2021 17:48:04 -0400 Subject: [PATCH] fix truncated bytes --- src/cache/fs.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cache/fs.rs b/src/cache/fs.rs index 28f7a41..1085c1f 100644 --- a/src/cache/fs.rs +++ b/src/cache/fs.rs @@ -181,7 +181,8 @@ impl Stream for ConcurrentFsStream { fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { // First, try to read from the file... - let mut bytes = [0; 1460].to_vec(); + // TODO: Might be more efficient to have a larger buffer + let mut bytes = [0; 8 * 1024].to_vec(); let mut buffer = ReadBuf::new(&mut bytes); match self.file.as_mut().poll_read(cx, &mut buffer) { Poll::Ready(Ok(_)) => (), @@ -198,7 +199,8 @@ impl Stream for ConcurrentFsStream { // 1. We are actually done. // 2. We read to the EOF while the writer is still writing to it. - // To handle the second case, we need to see the status the writer: + // To handle the second case, we need to see the status of the + // writer, and if it's done writing yet. if let Poll::Ready(Some(WritingStatus::Done(n))) = self.receiver.as_mut().poll_next_unpin(cx) @@ -227,6 +229,7 @@ impl Stream for ConcurrentFsStream { } else { // We have data! Give it to the reader! self.bytes_read += filled as u64; + bytes.truncate(filled); Poll::Ready(Some(Ok(bytes.into()))) } }