Simplify the signature of the PDFDataTransportStream constructor

Given that we need to pass in a `PDFDataRangeTransport`-instance a number of the needed parameters can be obtained from it, rather than having to specify them manually.
This commit is contained in:
Jonas Jenwald 2024-02-03 13:10:42 +01:00
parent 247af2ee09
commit 06cd278808
2 changed files with 13 additions and 26 deletions

View File

@ -405,18 +405,10 @@ function getDocument(src) {
const networkStreamPromise = new Promise(function (resolve) { const networkStreamPromise = new Promise(function (resolve) {
let networkStream; let networkStream;
if (rangeTransport) { if (rangeTransport) {
networkStream = new PDFDataTransportStream( networkStream = new PDFDataTransportStream(rangeTransport, {
{ disableRange,
length, disableStream,
initialData: rangeTransport.initialData, });
progressiveDone: rangeTransport.progressiveDone,
contentDispositionFilename:
rangeTransport.contentDispositionFilename,
disableRange,
disableStream,
},
rangeTransport
);
} else if (!data) { } else if (!data) {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
throw new Error("Not implemented: createPDFNetworkStream"); throw new Error("Not implemented: createPDFNetworkStream");

View File

@ -24,20 +24,15 @@ import { isPdfFile } from "./display_utils.js";
/** @implements {IPDFStream} */ /** @implements {IPDFStream} */
class PDFDataTransportStream { class PDFDataTransportStream {
constructor( constructor(
{ pdfDataRangeTransport,
length, { disableRange = false, disableStream = false }
initialData,
progressiveDone = false,
contentDispositionFilename = null,
disableRange = false,
disableStream = false,
},
pdfDataRangeTransport
) { ) {
assert( assert(
pdfDataRangeTransport, pdfDataRangeTransport,
'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.' 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.'
); );
const { length, initialData, progressiveDone, contentDispositionFilename } =
pdfDataRangeTransport;
this._queuedChunks = []; this._queuedChunks = [];
this._progressiveDone = progressiveDone; this._progressiveDone = progressiveDone;
@ -62,23 +57,23 @@ class PDFDataTransportStream {
this._fullRequestReader = null; this._fullRequestReader = null;
this._rangeReaders = []; this._rangeReaders = [];
this._pdfDataRangeTransport.addRangeListener((begin, chunk) => { pdfDataRangeTransport.addRangeListener((begin, chunk) => {
this._onReceiveData({ begin, chunk }); this._onReceiveData({ begin, chunk });
}); });
this._pdfDataRangeTransport.addProgressListener((loaded, total) => { pdfDataRangeTransport.addProgressListener((loaded, total) => {
this._onProgress({ loaded, total }); this._onProgress({ loaded, total });
}); });
this._pdfDataRangeTransport.addProgressiveReadListener(chunk => { pdfDataRangeTransport.addProgressiveReadListener(chunk => {
this._onReceiveData({ chunk }); this._onReceiveData({ chunk });
}); });
this._pdfDataRangeTransport.addProgressiveDoneListener(() => { pdfDataRangeTransport.addProgressiveDoneListener(() => {
this._onProgressiveDone(); this._onProgressiveDone();
}); });
this._pdfDataRangeTransport.transportReady(); pdfDataRangeTransport.transportReady();
} }
_onReceiveData({ begin, chunk }) { _onReceiveData({ begin, chunk }) {