2021-05-31 04:20:25 -04:00
|
|
|
const fs = require('fs')
|
|
|
|
const { FSPdfManager } = require('./FSPdfManager')
|
|
|
|
|
2021-06-23 09:14:28 -04:00
|
|
|
async function parseXrefTable(path, size, checkDeadline) {
|
2021-05-31 04:20:25 -04:00
|
|
|
if (size === 0) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
|
|
|
const file = await fs.promises.open(path)
|
|
|
|
try {
|
2021-06-23 09:14:28 -04:00
|
|
|
const manager = new FSPdfManager(0, { fh: file, size, checkDeadline })
|
2021-05-31 04:20:25 -04:00
|
|
|
|
|
|
|
await manager.ensureDoc('checkHeader')
|
2021-06-23 09:14:28 -04:00
|
|
|
checkDeadline('pdfjs: after checkHeader')
|
2021-05-31 04:20:25 -04:00
|
|
|
await manager.ensureDoc('parseStartXRef')
|
2021-06-23 09:14:28 -04:00
|
|
|
checkDeadline('pdfjs: after parseStartXRef')
|
2021-05-31 04:20:25 -04:00
|
|
|
await manager.ensureDoc('parse')
|
2021-06-23 09:14:28 -04:00
|
|
|
checkDeadline('pdfjs: after parse')
|
2021-05-31 04:20:25 -04:00
|
|
|
return manager.pdfDocument.catalog.xref.entries
|
|
|
|
} finally {
|
|
|
|
file.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2021-07-13 07:04:48 -04:00
|
|
|
parseXrefTable,
|
2021-05-31 04:20:25 -04:00
|
|
|
}
|