diff --git a/src/file.rs b/src/file.rs index 6f011e7..34348a5 100644 --- a/src/file.rs +++ b/src/file.rs @@ -8,7 +8,7 @@ pub(crate) use tokio_file::File; mod tokio_file { use crate::{store::file_store::FileError, Either}; use actix_web::web::{Bytes, BytesMut}; - use futures_util::stream::{Stream, StreamExt}; + use futures_util::{Stream, StreamExt, TryStreamExt}; use std::{io::SeekFrom, path::Path}; use tokio::io::{AsyncRead, AsyncReadExt, AsyncSeekExt, AsyncWrite, AsyncWriteExt}; use tokio_util::codec::{BytesCodec, FramedRead}; @@ -91,38 +91,7 @@ mod tokio_file { (None, None) => Either::right(self.inner), }; - Ok(BytesFreezer::new(FramedRead::new(obj, BytesCodec::new()))) - } - } - - pin_project_lite::pin_project! { - struct BytesFreezer { - #[pin] - inner: S, - } - } - - impl BytesFreezer { - fn new(inner: S) -> Self { - BytesFreezer { inner } - } - } - - impl Stream for BytesFreezer - where - S: Stream> + Unpin, - { - type Item = Result; - - fn poll_next( - mut self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - ) -> std::task::Poll> { - let this = self.as_mut().project(); - - this.inner - .poll_next(cx) - .map(|opt| opt.map(|res| res.map(BytesMut::freeze))) + Ok(FramedRead::new(obj, BytesCodec::new()).map_ok(BytesMut::freeze)) } } }