Comments (5)
Not sure if this behavior is intended but it was not indicated by the documentation or the source code.
It says 'with maximum size limit', which atleast to me, suggests that chunks may be smaller. But, feel free to make a PR to make it clearer.
I read that as a deliberate design. To have chunks of a fixed size would require not sending data that is already available, which could cause unnecessary delays.
from aiohttp.
Got it, thanks! So in order to get precise chunks of size N
, is it recommended to use readexactly(N)
? This was several orders of magnitude slower for my use case. I just ended up writing to a tempfile and reading out exactly sized chunks.
I think it's important to address these since the chunked reading feature is a widely used part of requests
and a lot of people expect exact analogues in aiohttp
.
I can make a PR updating docs. Let me know if there's any other relevant information/context.
from aiohttp.
I guess readexactly() works, or just adding chunks together yourself, maybe something like:
for new_chunk in ...:
chunk += new_chunk
if len(chunk) >= n:
process(chunk[:n])
chunk = chunk[n:]
I guess it's possible we could add an option if there's some solid use cases for it, but I'm not clear what those are yet. I think the main use case for the chunk size is to limit the amount of memory the application uses (e.g. downloading a large file and writing it to disk, on a tiny embedded system you may want to limit the amount of memory used for this to 1KB or something, while a desktop application might be good with 10MB as a limit).
from aiohttp.
My use case was for blowfish decryption, which was done on a chunk by chunk basis. This behavior was an issue because for any chunk with length n < chunk_size
# from iteration i from iteration i+1
decrypt(chunk[:n]) + decrypt(chunk[n:])
is not the same as
# from iteration i
decrypt(chunk)
which is what I want. I don't know any other use cases off the top of my head but I feel as though reading constant size blocks from a stream should be common enough.
from aiohttp.
This feels to me like an itertools job.
Something like batched(chain.from_iterable(resp.content.iter_chunked(n)), n)
should do it.
Looks like there are async versions of itertools at https://asyncstdlib.readthedocs.io/en/stable/source/api/itertools.html and https://aioitertools.omnilib.dev/en/stable/api.html (the former doesn't look like it has batched() yet, and the latter appears to have named it chunked()).
from aiohttp.
Related Issues (20)
- ValueError: I/O operation on closed file on WSL HOT 2
- Security improvement: raise_for_status + ClientError prevent tokens from leaking HOT 5
- Broken HTTP request parsing: Upgrade: h2c header leads to discarded body HOT 7
- aiohttp does not support concurrent requests exceeding 500.
- Termux aiohttp could not build wheels for aiohttp HOT 5
- aiohttp cannot make HTTPS (SSL) requests in a Windows container HOT 9
- DNS over HTTPS (DoH) HOT 1
- Unmonitored websocket task triggers false errors in logs HOT 1
- Documentation not working HOT 1
- https://docs.aiohttp.org/ has been defaced/squatted HOT 1
- aiohttp.org site is down HOT 1
- Server; POST-request; BadStatusLine: 400; an endless stream of exception messages that have no impact on operation.
- Broken timeout system with ws_connect HOT 1
- graceful shutdown order and cleanup contexts HOT 7
- ValueError: I/O operation on closed file in aiohttp payload size property on file uploading using form HOT 1
- Allow reading already retrieved response body after connection is closed
- Support for sending Trailer headers HOT 2
- Separate exception for DNS errors
- Weak Etag can not trigger negotiation caching
- The set request parameters were not used HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiohttp.