-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
tee
adaptor for AsnycRead
#4584
Comments
It could be reasonable to put something like it in tokio-util. |
Any objections to me tackling this? I think I see a couple of bugs in @arifd's example code, but I can fix them up as well as implement this for |
There are use cases like checking hashes of files that benefit from being able to inspect bytes read as they come in, while still letting the main code process the bytes as normal (e.g. deserializing into objects, knowing that if there's a hash failure, you'll discard the result). As this is non-trivial to get right (e.g. handling a `buf` that's not empty when passed to `poll_read`, add a wrapper `InspectReader` that gets this right, passing all newly read bytes to a supplied `FnMut` closure. Fixes: tokio-rs#4584
When writing things out, it's useful to be able to inspect the bytes that are being written and do things like hash them as they go past. This isn't trivial to get right, due to partial writes and efficiently handling vectored writes (if used). Provide an `InspectWriter` wrapper that gets this right, giving a supplied `FnMut` closure a chance to inspect the buffers that have been successfully written out. Fixes: tokio-rs#4584
When writing things out, it's useful to be able to inspect the bytes that are being written and do things like hash them as they go past. This isn't trivial to get right, due to partial writes and efficiently handling vectored writes (if used). Provide an `InspectWriter` wrapper that gets this right, giving a supplied `FnMut` closure a chance to inspect the buffers that have been successfully written out. Fixes: tokio-rs#4584
I've put together two commits in #5033 that provide wrappers for |
This can be closed now that #5033 has landed - it looks like I fouled up the linking of PR to issue, so it didn't happen automatically. |
Is your feature request related to a problem? Please describe.
As bytes were being streamed through, I needed a way to feed a copy of the bytes into a hashing function.
Describe the solution you'd like
What I ended up doing was basically implement this crate for
AsyncRead
Here is the full code:
Would something like this be suitable in
tokio_util
or maybefutures_util
?The text was updated successfully, but these errors were encountered: