mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
Re-factor setPDFNetworkStreamFactory
, in src/display/api.js, to also accept an asynchronous function
As part of trying to reduce the usage of SystemJS in the development viewer, this patch is a necessary step that will allow removal of some `require` statements. Currently this uses `SystemJS.import` in non-PRODUCTION mode, but it should be possible to replace those with standard *dynamic* `import` calls in the future.
This commit is contained in:
parent
0960e6c0b5
commit
d4d933538b
4 changed files with 72 additions and 32 deletions
|
@ -65,7 +65,8 @@ const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
|||
* @typedef {function} IPDFStreamFactory
|
||||
* @param {DocumentInitParameters} params - The document initialization
|
||||
* parameters. The "url" key is always present.
|
||||
* @returns {IPDFStream}
|
||||
* @returns {Promise} A promise, which is resolved with an instance of
|
||||
* {IPDFStream}.
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
|
@ -80,7 +81,7 @@ let createPDFNetworkStream;
|
|||
* data transport.
|
||||
* @param {IPDFStreamFactory} pdfNetworkStreamFactory - The factory function
|
||||
* that takes document initialization parameters (including a "url") and
|
||||
* returns an instance of {IPDFStream}.
|
||||
* returns a promise which is resolved with an instance of {IPDFStream}.
|
||||
* @ignore
|
||||
*/
|
||||
function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
||||
|
@ -313,34 +314,44 @@ function getDocument(src) {
|
|||
if (task.destroyed) {
|
||||
throw new Error("Loading aborted");
|
||||
}
|
||||
return _fetchDocument(worker, params, rangeTransport, docId).then(
|
||||
function (workerId) {
|
||||
if (task.destroyed) {
|
||||
throw new Error("Loading aborted");
|
||||
}
|
||||
|
||||
let networkStream;
|
||||
if (rangeTransport) {
|
||||
networkStream = new PDFDataTransportStream(
|
||||
{
|
||||
length: params.length,
|
||||
initialData: params.initialData,
|
||||
progressiveDone: params.progressiveDone,
|
||||
disableRange: params.disableRange,
|
||||
disableStream: params.disableStream,
|
||||
},
|
||||
rangeTransport
|
||||
);
|
||||
} else if (!params.data) {
|
||||
networkStream = createPDFNetworkStream({
|
||||
url: params.url,
|
||||
const workerIdPromise = _fetchDocument(
|
||||
worker,
|
||||
params,
|
||||
rangeTransport,
|
||||
docId
|
||||
);
|
||||
const networkStreamPromise = new Promise(function (resolve) {
|
||||
let networkStream;
|
||||
if (rangeTransport) {
|
||||
networkStream = new PDFDataTransportStream(
|
||||
{
|
||||
length: params.length,
|
||||
httpHeaders: params.httpHeaders,
|
||||
withCredentials: params.withCredentials,
|
||||
rangeChunkSize: params.rangeChunkSize,
|
||||
initialData: params.initialData,
|
||||
progressiveDone: params.progressiveDone,
|
||||
disableRange: params.disableRange,
|
||||
disableStream: params.disableStream,
|
||||
});
|
||||
},
|
||||
rangeTransport
|
||||
);
|
||||
} else if (!params.data) {
|
||||
networkStream = createPDFNetworkStream({
|
||||
url: params.url,
|
||||
length: params.length,
|
||||
httpHeaders: params.httpHeaders,
|
||||
withCredentials: params.withCredentials,
|
||||
rangeChunkSize: params.rangeChunkSize,
|
||||
disableRange: params.disableRange,
|
||||
disableStream: params.disableStream,
|
||||
});
|
||||
}
|
||||
resolve(networkStream);
|
||||
});
|
||||
|
||||
return Promise.all([workerIdPromise, networkStreamPromise]).then(
|
||||
function ([workerId, networkStream]) {
|
||||
if (task.destroyed) {
|
||||
throw new Error("Loading aborted");
|
||||
}
|
||||
|
||||
const messageHandler = new MessageHandler(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue