Skip to content
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

A question about stream.read() #1044

Closed
llnancy opened this issue Oct 9, 2023 · 2 comments
Closed

A question about stream.read() #1044

llnancy opened this issue Oct 9, 2023 · 2 comments

Comments

@llnancy
Copy link

llnancy commented Oct 9, 2023

        # get object from s3
        response = await client.get_object(Bucket=bucket, Key=key)
        # this will ensure the connection is correctly re-used/closed
        async with response['Body'] as stream:
            assert await stream.read() == data

For large files (more than GB), stream.read() will cause OOM. Are there any examples of segmented reading?

@jakob-keller
Copy link
Collaborator

Awaiting stream.read() will read the whole response’s body as bytes, potentially resulting in OOM issues.

You may want to look at stream.content and the StreamReader reading methods.

I hope this points you in the right direction.

@thehesiod
Copy link
Collaborator

there's also the StreamingBody helpers:

class StreamingBody(wrapt.ObjectProxy):
which mimics the version from botocore available via response['Body']

@llnancy llnancy closed this as completed Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants