2

Using the below code I can have the size in bytes of my (stream) file:

let bytes_copied = tokio::io::copy(&mut stream, &mut file).await?;

Is there a way I can have the size of the (stream) file using rust-s3 methods (https://github.com/durch/rust-s3) ?

bucket.put_object_stream(&mut stream, filename).await?;

Or Is there a way to "count" bytes as they "pass" in this "stream tunnel"?

Fred Hors
  • 3,258
  • 3
  • 25
  • 71
  • You could write a wrapper around your stream that also implements `Read`. In this wrapper, you'd increase the counter yourself on reads and forward everything else to the underlying concrete (or generic) reader. Kind of along [those lines](https://github.com/ChainSafe/forest/blob/main/utils/forest_utils/src/io/writer_checksum.rs) I implemented some time ago, but for a reader. – Leśny Rumcajs Dec 13 '22 at 17:40
  • Isn't this what the inspect iterator/stream combinator is for? Could you use that? – MeetTitan Dec 13 '22 at 21:31
  • MeedTitan, can you please/link an example? I don't know what are you talking about... – Fred Hors Dec 13 '22 at 22:52
  • Does this answer your question? [How to get callback/update when using tokio::io::copy?](/q/60621835/2189130) – kmdreko Dec 30 '22 at 01:43

0 Answers0