mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 08:38:06 +02:00
Inline the _fetchDocument
helper function in getDocument
This function has been modified a number of times over the years, and at this point it's small/simple enough that we can just inline the code instead.
This commit is contained in:
parent
33f3228e00
commit
cbb8748a22
1 changed files with 13 additions and 28 deletions
|
@ -357,7 +357,7 @@ function getDocument(src) {
|
|||
task._worker = worker;
|
||||
}
|
||||
|
||||
const fetchDocParams = {
|
||||
const docParams = {
|
||||
docId,
|
||||
apiVersion:
|
||||
typeof PDFJSDev !== "undefined" && !PDFJSDev.test("TESTING")
|
||||
|
@ -398,9 +398,16 @@ function getDocument(src) {
|
|||
if (task.destroyed) {
|
||||
throw new Error("Loading aborted");
|
||||
}
|
||||
if (worker.destroyed) {
|
||||
throw new Error("Worker was destroyed");
|
||||
}
|
||||
|
||||
const workerIdPromise = _fetchDocument(worker, fetchDocParams);
|
||||
const networkStreamPromise = new Promise(function (resolve) {
|
||||
const workerIdPromise = worker.messageHandler.sendWithPromise(
|
||||
"GetDocRequest",
|
||||
docParams,
|
||||
data ? [data.buffer] : null
|
||||
);
|
||||
const networkStreamPromise = new Promise(resolve => {
|
||||
let networkStream;
|
||||
if (rangeTransport) {
|
||||
networkStream = new PDFDataTransportStream(rangeTransport, {
|
||||
|
@ -451,6 +458,9 @@ function getDocument(src) {
|
|||
if (task.destroyed) {
|
||||
throw new Error("Loading aborted");
|
||||
}
|
||||
if (worker.destroyed) {
|
||||
throw new Error("Worker was destroyed");
|
||||
}
|
||||
|
||||
const messageHandler = new MessageHandler(
|
||||
docId,
|
||||
|
@ -474,31 +484,6 @@ function getDocument(src) {
|
|||
return task;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts fetching of specified PDF document/data.
|
||||
*
|
||||
* @param {PDFWorker} worker
|
||||
* @param {Object} source
|
||||
* @returns {Promise<string>} A promise that is resolved when the worker ID of
|
||||
* the `MessageHandler` is known.
|
||||
* @private
|
||||
*/
|
||||
async function _fetchDocument(worker, source) {
|
||||
if (worker.destroyed) {
|
||||
throw new Error("Worker was destroyed");
|
||||
}
|
||||
const workerId = await worker.messageHandler.sendWithPromise(
|
||||
"GetDocRequest",
|
||||
source,
|
||||
source.data ? [source.data.buffer] : null
|
||||
);
|
||||
|
||||
if (worker.destroyed) {
|
||||
throw new Error("Worker was destroyed");
|
||||
}
|
||||
return workerId;
|
||||
}
|
||||
|
||||
function getUrlProp(val) {
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||
return null; // The 'url' is unused with `PDFDataRangeTransport`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue