Skip to content

Commit 5412dd3

Browse files
authored
DOC: PdfReader private functions (#1662)
1 parent 5b4bb27 commit 5412dd3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pypdf/_reader.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,7 @@ def read(self, stream: StreamType) -> None:
15371537
stream.seek(loc, 0) # return to where it was
15381538

15391539
def _basic_validation(self, stream: StreamType) -> None:
1540+
"""Ensure file is not empty. Read at most 5 bytes."""
15401541
# start at the end:
15411542
stream.seek(0, os.SEEK_END)
15421543
if not stream.tell():
@@ -1552,10 +1553,17 @@ def _basic_validation(self, stream: StreamType) -> None:
15521553
stream.seek(0, os.SEEK_END)
15531554

15541555
def _find_eof_marker(self, stream: StreamType) -> None:
1555-
last_mb = 8 # to parse whole file
1556+
"""
1557+
Jump to the %%EOF marker.
1558+
1559+
According to the specs, the %%EOF marker should be at the very end of
1560+
the file. Hence for standard-compliant PDF documents this function will
1561+
read only the last part (DEFAULT_BUFFER_SIZE).
1562+
"""
1563+
HEADER_SIZE = 8 # to parse whole file, Header is e.g. '%PDF-1.6'
15561564
line = b""
15571565
while line[:5] != b"%%EOF":
1558-
if stream.tell() < last_mb:
1566+
if stream.tell() < HEADER_SIZE:
15591567
raise PdfReadError("EOF marker not found")
15601568
line = read_previous_line(stream)
15611569

0 commit comments

Comments
 (0)