Skip to content

Wrapping an AsyncRead + AsyncWrite stream #296

@link2xt

Description

@link2xt

I have a AsyncRead + AsyncWrite network stream that I want to compress, like a TcpStream or TlsStream.

Is there a way to wrap such stream to get a single CompressedStream with async-compress?

If I use tokio::io::split and then wrap each part in e.g. DeflateEncoder and DeflateDecoder separately, I get two separate objects and not a single stream anymore. Besides, split adds overhead by placing the inner stream behind a mutex. In chatmail/async-imap#112 I manually placed the stream behind a mutex to pass it into DeflateEncoder and DeflateDecoder, so at least I have an access to inner stream, but now I cannot have a get_ref() and get_mut() API on the resulting stream because it is behind a mutex internally.

What I want is some API like a compressed stream builder which gets encoder, decoder and underlying stream and constructs a single object that allows direct access to underlying stream via get_ref() and get_mut(). Is it impossible with async-compression?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions