MCPcopy Create free account
hub / github.com/LibPDF-js/core / detectXRefFormat

Method detectXRefFormat

src/parser/xref-parser.ts:117–133  ·  view source on GitHub ↗

* Detect the XRef format at a given offset without fully parsing. * * @returns true if XRef stream, false if table, null if cannot detect

(offset: number)

Source from the content-addressed store, hash-verified

115 * @returns true if XRef stream, false if table, null if cannot detect
116 */
117 detectXRefFormat(offset: number): boolean | null {
118 this.scanner.moveTo(offset);
119
120 const firstByte = this.scanner.peek();
121
122 // 'x' = 0x78 starts "xref" (table format)
123 if (firstByte === 0x78) {
124 return false;
125 }
126
127 // Digit starts "N M obj" (stream format)
128 if (firstByte >= DIGIT_0 && firstByte <= DIGIT_9) {
129 return true;
130 }
131
132 return null;
133 }
134
135 /**
136 * Parse traditional xref table format.

Callers 2

loadMethod · 0.95
reloadMethod · 0.95

Calls 2

moveToMethod · 0.65
peekMethod · 0.45

Tested by

no test coverage detected