Skip to content

fix: copy cached attachment in chunks via shutil.copyfileobj#252

Open
Flerpharos wants to merge 1 commit into
mainfrom
fix/215-get-attachment-chunked-copy
Open

fix: copy cached attachment in chunks via shutil.copyfileobj#252
Flerpharos wants to merge 1 commit into
mainfrom
fix/215-get-attachment-chunked-copy

Conversation

@Flerpharos

Copy link
Copy Markdown
Collaborator

Summary

get_attachment(use_tempfile=True) called self._filedata.read() with no size argument, materializing the entire cached payload as one bytes object before writing it to the output tempfile. This defeats the memory-saving purpose of use_tempfile=True for large attachments.

Fix

Replace output.write(self._filedata.read()) with shutil.copyfileobj(self._filedata, output), which copies in bounded chunks (default 64 KB).

Closes #215

get_attachment(use_tempfile=True) called self._filedata.read() with no
size argument, materializing the entire cached payload as one bytes object
before writing it to the output tempfile. This defeats the memory-saving
purpose of use_tempfile=True for large attachments.

Replace with shutil.copyfileobj which copies in bounded chunks (default
64 KB).

Closes #215
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

Successfully merging this pull request may close these issues.

get_attachment(use_tempfile=True) still reads the full attachment into memory

1 participant