Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions crates/async-compression/src/generic/write/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Default for Decoder {
}

impl Decoder {
pub fn do_poll_write(
fn do_poll_write(
&mut self,
cx: &mut Context<'_>,
input: &mut PartialBuffer<&[u8]>,
Expand Down Expand Up @@ -73,6 +73,25 @@ impl Decoder {
}
}

pub fn poll_write(
&mut self,
cx: &mut Context<'_>,
buf: &[u8],
writer: Pin<&mut dyn AsyncBufWrite>,
decoder: &mut impl Decode,
) -> Poll<io::Result<usize>> {
if buf.is_empty() {
return Poll::Ready(Ok(0));
}

let mut input = PartialBuffer::new(buf);

match self.do_poll_write(cx, &mut input, writer, decoder)? {
Poll::Pending if input.written().is_empty() => Poll::Pending,
_ => Poll::Ready(Ok(input.written().len())),
}
}

pub fn do_poll_flush(
&mut self,
cx: &mut Context<'_>,
Expand Down Expand Up @@ -169,17 +188,6 @@ macro_rules! impl_decoder {
}

impl<W: AsyncWrite, D: Decode> Decoder<W, D> {
fn do_poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
input: &mut PartialBuffer<&[u8]>,
) -> Poll<io::Result<()>> {
let mut this = self.project();

this.inner
.do_poll_write(cx, input, this.writer, this.decoder)
}

fn do_poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
let mut this = self.project();

Expand All @@ -193,16 +201,9 @@ macro_rules! impl_decoder {
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
if buf.is_empty() {
return Poll::Ready(Ok(0));
}

let mut input = PartialBuffer::new(buf);
let mut this = self.project();

match self.do_poll_write(cx, &mut input)? {
Poll::Pending if input.written().is_empty() => Poll::Pending,
_ => Poll::Ready(Ok(input.written().len())),
}
this.inner.poll_write(cx, buf, this.writer, this.decoder)
}

fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
Expand Down