theelous3 / asks

Async requests-like httplib for python.
MIT License
508 stars 63 forks source link

Receive only a certain amount of bytes in StreamBody #109

Open lordi opened 5 years ago

lordi commented 5 years ago

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?

theelous3 commented 5 years ago

I think this is a good idea!

On Tue 26 Feb 2019, 7:31 a.m. Hannes Gräuler, notifications@github.com 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 commented 5 years ago

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.