mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 11:21:24 +00:00
Remove custom BytesFreezer stream
This commit is contained in:
parent
25f4480809
commit
0e490ff54a
1 changed files with 2 additions and 33 deletions
35
src/file.rs
35
src/file.rs
|
@ -8,7 +8,7 @@ pub(crate) use tokio_file::File;
|
||||||
mod tokio_file {
|
mod tokio_file {
|
||||||
use crate::{store::file_store::FileError, Either};
|
use crate::{store::file_store::FileError, Either};
|
||||||
use actix_web::web::{Bytes, BytesMut};
|
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 std::{io::SeekFrom, path::Path};
|
||||||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncSeekExt, AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncRead, AsyncReadExt, AsyncSeekExt, AsyncWrite, AsyncWriteExt};
|
||||||
use tokio_util::codec::{BytesCodec, FramedRead};
|
use tokio_util::codec::{BytesCodec, FramedRead};
|
||||||
|
@ -91,38 +91,7 @@ mod tokio_file {
|
||||||
(None, None) => Either::right(self.inner),
|
(None, None) => Either::right(self.inner),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(BytesFreezer::new(FramedRead::new(obj, BytesCodec::new())))
|
Ok(FramedRead::new(obj, BytesCodec::new()).map_ok(BytesMut::freeze))
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pin_project_lite::pin_project! {
|
|
||||||
struct BytesFreezer<S> {
|
|
||||||
#[pin]
|
|
||||||
inner: S,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<S> BytesFreezer<S> {
|
|
||||||
fn new(inner: S) -> Self {
|
|
||||||
BytesFreezer { inner }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<S, E> Stream for BytesFreezer<S>
|
|
||||||
where
|
|
||||||
S: Stream<Item = Result<BytesMut, E>> + Unpin,
|
|
||||||
{
|
|
||||||
type Item = Result<Bytes, E>;
|
|
||||||
|
|
||||||
fn poll_next(
|
|
||||||
mut self: std::pin::Pin<&mut Self>,
|
|
||||||
cx: &mut std::task::Context<'_>,
|
|
||||||
) -> std::task::Poll<Option<Self::Item>> {
|
|
||||||
let this = self.as_mut().project();
|
|
||||||
|
|
||||||
this.inner
|
|
||||||
.poll_next(cx)
|
|
||||||
.map(|opt| opt.map(|res| res.map(BytesMut::freeze)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue