ByteReader

class ByteReader(val bytes: ByteArray)

Random-access byte cursor over an in-memory PDF.

PDF parsing is fundamentally backward-and-forward: we read the trailer from end-of-file, jump to the xref table, then resolve indirect objects by seeking to byte offsets. So the reader exposes seek/pos/peek/read, not a stream API.

Everything is byte-level — PDF syntax is ASCII-ish but binary-safe inside streams and strings, so we never call String(...) on the underlying bytes outside controlled paths.

Constructors

Link copied to clipboard
constructor(bytes: ByteArray)

Properties

Link copied to clipboard
Link copied to clipboard
val size: Int

Functions

Link copied to clipboard
fun advance(n: Int)
Link copied to clipboard
Link copied to clipboard
fun lastIndexOf(needle: ByteArray, from: Int = bytes.size - needle.size): Int

Find the LAST occurrence of needle at or before from. Returns -1 if not found.

Link copied to clipboard
fun matches(needle: ByteArray, at: Int = position): Boolean

True if the next bytes match needle (ASCII), without advancing.

Link copied to clipboard
fun peek(): Int

Peek one byte without advancing; returns -1 at EOF.

fun peek(offset: Int): Int

Peek byte at offset bytes ahead without advancing; returns -1 at EOF.

Link copied to clipboard
fun pos(): Int
Link copied to clipboard
fun readByte(): Int

Read one byte and advance; returns -1 at EOF.

Link copied to clipboard
fun readBytes(length: Int): ByteArray

Read length bytes from current position into a new array and advance.

Link copied to clipboard
fun remaining(): Int
Link copied to clipboard
fun seek(offset: Int)
Link copied to clipboard
fun unread()

Step back one byte. Used by lexer for "I read too far" lookahead.