]>
git.proxmox.com Git - proxmox-backup.git/blob - src/tools/wrapped_reader_stream.rs
5 use futures
::stream
::Stream
;
7 pub struct WrappedReaderStream
<R
: Read
> {
11 impl <R
: Read
> WrappedReaderStream
<R
> {
13 pub fn new(reader
: R
) -> Self {
18 fn blocking_err() -> std
::io
::Error
{
20 std
::io
::ErrorKind
::Other
,
21 "`blocking` annotated I/O must be called from the context of the Tokio runtime.")
24 impl <R
: Read
> Stream
for WrappedReaderStream
<R
> {
27 type Error
= std
::io
::Error
;
29 fn poll(&mut self) -> Result
<Async
<Option
<Vec
<u8>>>, std
::io
::Error
> {
30 let mut buf
= [0u8;64*1024];
31 match tokio_threadpool
::blocking(|| self.reader
.read(&mut buf
)) {
32 Ok(Async
::Ready(Ok(n
))) => {
34 Ok(Async
::Ready(None
))
36 Ok(Async
::Ready(Some(buf
[..n
].to_vec())))
39 Ok(Async
::Ready(Err(err
))) => Err(err
),
40 Ok(Async
::NotReady
) => Ok(Async
::NotReady
),
41 Err(err
) => Err(blocking_err()),