Add buffered reader again

This commit is contained in:
Edward Shen 2021-04-22 20:01:11 -04:00
parent 84ea4bea89
commit b01fa618b4
Signed by: edward
GPG key ID: 19182661E818369F
2 changed files with 6 additions and 6 deletions

8
src/cache/fs.rs vendored
View file

@ -12,7 +12,7 @@ use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::task::{Context, Poll};
use tokio::fs::{create_dir_all, remove_file, File};
use tokio::io::{AsyncRead, AsyncSeekExt, AsyncWriteExt, ReadBuf};
use tokio::io::{AsyncRead, AsyncSeekExt, AsyncWriteExt, BufReader, ReadBuf};
use tokio::sync::mpsc::UnboundedSender;
use tokio::sync::watch::{channel, Receiver};
use tokio::sync::RwLock;
@ -61,7 +61,7 @@ pub async fn read_file(
WatchStream::new(status),
))
} else {
CacheStream::Completed(FramedRead::new(file, BytesCodec::new()))
CacheStream::Completed(FramedRead::new(BufReader::new(file), BytesCodec::new()))
};
Some(Ok((stream, metadata)))
@ -156,7 +156,7 @@ pub async fn write_file(
}
pub struct ConcurrentFsStream {
file: Pin<Box<File>>,
file: Pin<Box<BufReader<File>>>,
receiver: Pin<Box<WatchStream<WritingStatus>>>,
bytes_read: u64,
bytes_total: Option<NonZeroU64>,
@ -175,7 +175,7 @@ impl ConcurrentFsStream {
fn from_file(file: File, receiver: WatchStream<WritingStatus>) -> Self {
Self {
file: Box::pin(file),
file: Box::pin(BufReader::new(file)),
receiver: Box::pin(receiver),
bytes_read: 0,
bytes_total: None,

4
src/cache/mod.rs vendored
View file

@ -12,7 +12,7 @@ use fs::ConcurrentFsStream;
use futures::{Stream, StreamExt};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use tokio::fs::File;
use tokio::{fs::File, io::BufReader};
use tokio_util::codec::{BytesCodec, FramedRead};
pub use fs::UpstreamError;
@ -170,7 +170,7 @@ pub trait Cache: Send + Sync {
pub enum CacheStream {
Concurrent(ConcurrentFsStream),
Memory(MemStream),
Completed(FramedRead<File, BytesCodec>),
Completed(FramedRead<BufReader<File>, BytesCodec>),
}
impl From<CachedImage> for CacheStream {