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

Method parseEntry

src/parser/xref-parser.ts:397–428  ·  view source on GitHub ↗

* Parse a single xref entry. * Format: OOOOOOOOOO GGGGG T (10-digit offset, 5-digit gen, type)

()

Source from the content-addressed store, hash-verified

395 * Format: OOOOOOOOOO GGGGG T (10-digit offset, 5-digit gen, type)
396 */
397 private parseEntry(): XRefEntry {
398 // Read 10-digit offset
399 const offset = this.readFixedDigits(10);
400 this.skipSpaces();
401
402 // Read 5-digit generation
403 const generation = this.readFixedDigits(5);
404 this.skipSpaces();
405
406 // Read type: 'n' or 'f'
407 const typeByte = this.scanner.advance();
408
409 // Skip to end of entry (EOL)
410 this.skipToEOL();
411 this.skipEOL();
412
413 if (typeByte === CHAR_n) {
414 return {
415 type: "uncompressed",
416 offset,
417 generation,
418 };
419 } else if (typeByte === CHAR_f) {
420 return {
421 type: "free",
422 nextFree: offset, // For free entries, offset field is next free object
423 generation,
424 };
425 } else {
426 throw new XRefParseError(`Invalid xref entry type: ${String.fromCharCode(typeByte)}`);
427 }
428 }
429
430 /**
431 * Read a fixed number of digits as an integer.

Callers 1

parseSubsectionMethod · 0.95

Calls 5

readFixedDigitsMethod · 0.95
skipSpacesMethod · 0.95
skipToEOLMethod · 0.95
skipEOLMethod · 0.95
advanceMethod · 0.80

Tested by

no test coverage detected