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 21, 2024
1 parent 5209fcd commit 1f81b68
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pypdf/_reader.py
Expand Up @@ -314,10 +314,10 @@ def __init__(
__name__,
)

self._we_opened = False
self._opened_automatically = False
if isinstance(stream, (str, Path)):
stream = FileIO(stream, "rb")
self._we_opened = True
self._opened_automatically = True
weakref.finalize(self, stream.close)

self.read(stream)
Expand Down Expand Up @@ -363,8 +363,8 @@ def __exit__(
exc: Optional[BaseException],
traceback: Optional[TracebackType],
) -> None:
"""Write data to the fileobj."""
if self._we_opened:
"""Close the underlying stream if owned by the PdfReader"""
if self._opened_automatically:
self.close()

@property
Expand Down

0 comments on commit 1f81b68

Please sign in to comment.