My use case is:
I'm using tokio
. I'm receiving Base64-encoded bytes via an async stream. I want to decode the bytes on the fly, and send the decoded bytes to their destination (a tokio::fs::File
).
The decoder in the base64
crate supports Read
inputs, but not AsyncRead
. I couldn't find any crates that do support AsyncRead
.
I think I can work around this by using spawn_blocking()
:
- Send the base64-encoded bytes to a
tokio
channel - Use
spawn_blocking()
to run a synchronous task that decodes them, and sends the decoded bytes to a secondtokio
channel. - Have another
tokio
task that receives the decode bytes and sends them to their final destination.
This is my fallback, but it's a bit clunky, to say the least.
Really what I need is a "stateful" base64 decoder, one to which I can submit the next batch of input bytes, and get back the next batch of decoded bytes (if any). I looked at the crates base64, base64ct, and base64-stream, but none of them provide a stateful decoder (base64ct
supports "incremental decoding", but you still have to supply all the encoded data up front).
Does anyone know of a stateful Base64 decoder, or a way of decoding an async stream on the fly?