Skip to content

Commit 1f81b68

Browse files
committed
fixup! PI: Don't load entire file into memory when passed file name
1 parent 5209fcd commit 1f81b68

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pypdf/_reader.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ def __init__(
314314
__name__,
315315
)
316316

317-
self._we_opened = False
317+
self._opened_automatically = False
318318
if isinstance(stream, (str, Path)):
319319
stream = FileIO(stream, "rb")
320-
self._we_opened = True
320+
self._opened_automatically = True
321321
weakref.finalize(self, stream.close)
322322

323323
self.read(stream)
@@ -363,8 +363,8 @@ def __exit__(
363363
exc: Optional[BaseException],
364364
traceback: Optional[TracebackType],
365365
) -> None:
366-
"""Write data to the fileobj."""
367-
if self._we_opened:
366+
"""Close the underlying stream if owned by the PdfReader"""
367+
if self._opened_automatically:
368368
self.close()
369369

370370
@property

0 commit comments

Comments
 (0)