1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#![cfg(feature = "async-io")]
use super::AsyncBufReadDecompressor;
use crate::lz4f::{FrameInfo, Result};
use async_std::io::BufReader;
use futures_lite::AsyncRead;
use pin_project::pin_project;
use std::{
borrow::Cow,
fmt, io,
pin::Pin,
task::{Context, Poll},
};
#[cfg_attr(docsrs, doc(cfg(feature = "async-io")))]
#[pin_project]
pub struct AsyncReadDecompressor<'a, R: AsyncRead + Unpin> {
#[pin]
inner: AsyncBufReadDecompressor<'a, BufReader<R>>,
}
impl<'a, R: AsyncRead + Unpin> AsyncReadDecompressor<'a, R> {
pub fn new(reader: R) -> Result<Self> {
Ok(Self {
inner: AsyncBufReadDecompressor::new(BufReader::new(reader))?,
})
}
pub fn set_dict<D>(&mut self, dict: D)
where
D: Into<Cow<'a, [u8]>>,
{
self.inner.set_dict(dict);
}
pub async fn read_frame_info(&mut self) -> io::Result<FrameInfo> {
self.inner.read_frame_info().await
}
pub fn get_mut(&mut self) -> &mut R {
self.inner.get_mut().get_mut()
}
pub fn get_ref(&self) -> &R {
self.inner.get_ref().get_ref()
}
pub fn into_inner(self) -> R {
self.inner.into_inner().into_inner()
}
}
impl<R> fmt::Debug for AsyncReadDecompressor<'_, R>
where
R: AsyncRead + Unpin + fmt::Debug,
{
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("AsyncReadDecompressor")
.field("reader", &self.inner.inner.get_ref())
.finish()
}
}
impl<'a, R: AsyncRead + Unpin> AsyncRead for AsyncReadDecompressor<'a, R> {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
self.project().inner.poll_read(cx, buf)
}
}