Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl AsyncBufRead for Decoder #289

Closed
DrewMcArthur opened this issue Jul 30, 2024 · 4 comments
Closed

impl AsyncBufRead for Decoder #289

DrewMcArthur opened this issue Jul 30, 2024 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@DrewMcArthur
Copy link

Hi! So I've got a stream: impl AsyncBufRead, which may or may not be gzipped. I'm trying to return that stream in a function whose return type is Result<impl AsyncBufRead, Error>, but running into the issue where the GzipDecoder is AsyncRead, but not AsyncBufRead. Since the inner reader it pulls from is AsyncBufRead, is there any reason why the decoder itself can't be AsyncBufRead?

Or, am I misreading the docs, and I should just be calling into_inner()? the way I read it currently, this returns the original stream though, not the decoded version.

If it's easier, I just need this for the GzipDecoder, but I assume this level would be generic across all the Decoders.

@robjtede robjtede added the enhancement New feature or request label Jul 31, 2024
@DrewMcArthur
Copy link
Author

update: I was able to update my function to return a Box<dyn AsyncRead>, which covers both the GZipped case (returning a GzipDecoder: AsyncRead) and the plain filestream from S3 (returning an impl AsyncBufRead, which also is AsyncRead). Since my parsing function downstream just needs a Stream<Item=Bytes>, that's all I needed.

I'm still very curious what it would take to implement AsyncBufRead for the Decoder. I tried messing around with it a bit last night, but I'm too unfamiliar with Pins and all of that.

@robjtede robjtede added the good first issue Good for newcomers label Aug 7, 2024
@link2xt
Copy link
Contributor

link2xt commented Oct 15, 2024

Is this about bufread GzipDecoder? For write GzipDecoder #304 is going to pass through AsyncBufRead trait if underlying stream has it. For bufread GzipDecoder I think it makes sense that even though underlying stream may have a buffer, this is a buffer for gzipped data, so decoder implements AsyncRead which reads decompressed data into user-provided buffer and if you want the stream itself to have a buffer for decoded/decompressed data, you need to wrap it again into BufReader.

@robjtede
Copy link
Member

#304 was implemented and released.

If there's more to do for this issue please say so and we'll get it re-opened.

@DrewMcArthur
Copy link
Author

thank you @robjtede and @link2xt !! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants