We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 389b579 commit 81dcf46Copy full SHA for 81dcf46
pypdf/_reader.py
@@ -47,6 +47,7 @@
47
Union,
48
cast,
49
)
50
+import weakref
51
52
from ._encryption import Encryption, PasswordType
53
from ._page import PageObject, _VirtualList
@@ -310,9 +311,11 @@ def __init__(
310
311
"It may not be read correctly.",
312
__name__,
313
314
+
315
if isinstance(stream, (str, Path)):
- with open(stream, "rb") as fh:
- stream = BytesIO(fh.read())
316
+ stream = open(stream, "rb")
317
+ self._finalizer = weakref.finalize(self, stream.close)
318
319
self.read(stream)
320
self.stream = stream
321
0 commit comments