asks icon indicating copy to clipboard operation
asks copied to clipboard

Receive only a certain amount of bytes in StreamBody

Open lordi opened this issue 5 years ago • 2 comments

Is it possible to not use the stream body as an iterator, but to read from it like from a file? I'd like to do read(2048) for example to read the next 2048 bytes.

I skipped around the source a little bit, and it looks like _recv_event is the function that does it, but it has 10000 as a hardcoded read limit.

What do you think about adding to a public function read function to StreamBody?

lordi avatar Feb 26 '19 07:02 lordi

I think this is a good idea!

On Tue 26 Feb 2019, 7:31 a.m. Hannes Gräuler, [email protected] wrote:

Is it possible to not use the stream body as an iterator, but to read from it like from a file? I'd like to do read(2048) for example to read the next 2048 bytes.

I skipped around the source a little bit, and it looks like _recv_event is the function that does it, but it has 10000 as a hardcoded read limit.

What do you think about adding to a public function read function to StreamBody?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/theelous3/asks/issues/109, or mute the thread https://github.com/notifications/unsubscribe-auth/ASa9SpPLkLnMIDJR70PrA0s6u7x4zy21ks5vROLrgaJpZM4bRh-6 .

theelous3 avatar Feb 26 '19 10:02 theelous3

So, my only issue with this is that decompression and encoding goes out the window as soon as we set our own limits, rather than let h11 handle it.

In the meantime I've added an attr, StreamBody.read_size so at least that can be controlled. Need to think about how to nicely handle arbitrary reads.

theelous3 avatar Mar 13 '19 20:03 theelous3