mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
294088fb27
* make the content cache manager tests configurable * extend stream content in unit tests * [ContentCacheManagerTests] prepare for full object caching * filesystem stream for pdfjs * working?? * cleaning up * handle overflow * [misc] install pdfjs-dist * [misc] move pdfjs code into app/lib/ and scripts/, also use CamelCase * [misc] abstract the file loading and parsing of xRef tables into helper * [misc] pdfjsTests: add snapshot based tests for the Xref table parser * [misc] FSStream: throw proper error and drop commented code * [misc] FSStream: integrate throwing of MissingDataException into getter * [misc] pdfjs: fix eslint errors * [misc] pdfjs: run format_fix * [misc] pdfjs: allocate very small non empty dummy buffers explicitly * [misc] install @overleaf/o-error * [ContentCacheManager] use PDF.js Xref table instead of stream detection Co-Authored-By: Brian Gough <brian.gough@overleaf.com> * [pdfjs] parseXrefTable: handle empty PDF files gracefully Co-authored-by: Brian Gough <brian.gough@overleaf.com>
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
const { PDFDocument } = require('pdfjs-dist/lib/core/document')
|
|
const { LocalPdfManager } = require('pdfjs-dist/lib/core/pdf_manager')
|
|
const { MissingDataException } = require('pdfjs-dist/lib/core/core_utils')
|
|
const { FSStream } = require('./FSStream')
|
|
|
|
class FSPdfManager extends LocalPdfManager {
|
|
constructor(docId, options) {
|
|
const nonEmptyDummyBuffer = Buffer.alloc(1, 0)
|
|
super(docId, nonEmptyDummyBuffer)
|
|
this.stream = new FSStream(options.fh, 0, options.size)
|
|
this.pdfDocument = new PDFDocument(this, this.stream)
|
|
}
|
|
|
|
async ensure(obj, prop, args) {
|
|
try {
|
|
const value = obj[prop]
|
|
if (typeof value === 'function') {
|
|
return value.apply(obj, args)
|
|
}
|
|
return value
|
|
} catch (ex) {
|
|
if (!(ex instanceof MissingDataException)) {
|
|
throw ex
|
|
}
|
|
await this.requestRange(ex.begin, ex.end)
|
|
return this.ensure(obj, prop, args)
|
|
}
|
|
}
|
|
|
|
requestRange(begin, end) {
|
|
return this.stream.requestRange(begin, end)
|
|
}
|
|
|
|
requestLoadedStream() {}
|
|
|
|
onLoadedStream() {}
|
|
|
|
terminate(reason) {}
|
|
}
|
|
|
|
module.exports = {
|
|
FSPdfManager
|
|
}
|