Skip to content

Commit

Permalink
fixup! PI: Don't load entire file into memory when passed file name
Browse files Browse the repository at this point in the history
  • Loading branch information
mjsir911 committed Mar 15, 2024
1 parent 9ccce80 commit 1a4b1af
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions pypdf/_reader.py
Expand Up @@ -314,6 +314,7 @@ def __init__(

if isinstance(stream, (str, Path)):
stream = open(stream, "rb") # noqa: SIM115
# Wish I could just close stream in __del__ but that fails a test very strangely
weakref.finalize(self, stream.close)

self.read(stream)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_writer.py
Expand Up @@ -1234,6 +1234,7 @@ def test_set_page_label(pdf_file_path):
writer.set_page_label(0, 1, "/A")
writer.write(pdf_file_path)
assert PdfReader(pdf_file_path).page_labels[: len(expected)] == expected
del writer

pdf_file_path.unlink()

Expand Down Expand Up @@ -1477,6 +1478,7 @@ def test_update_form_fields(tmp_path):
)

writer.write(write_data_here)
del writer
reader = PdfReader(write_data_here)
flds = reader.get_fields()
assert flds["CheckBox1"]["/V"] == "/Yes"
Expand Down

0 comments on commit 1a4b1af

Please sign in to comment.