diff --git a/src/display/fetch_stream.js b/src/display/fetch_stream.js index 79fca1f71..7cb1f3c8c 100644 --- a/src/display/fetch_stream.js +++ b/src/display/fetch_stream.js @@ -190,12 +190,11 @@ class PDFFetchStreamReader { return { value, done }; } this._loaded += value.byteLength; - if (this.onProgress) { - this.onProgress({ - loaded: this._loaded, - total: this._contentLength, - }); - } + this.onProgress?.({ + loaded: this._loaded, + total: this._contentLength, + }); + const buffer = new Uint8Array(value).buffer; return { value: buffer, done: false }; } diff --git a/src/display/node_stream.js b/src/display/node_stream.js index 84d9b9a1b..44866fbc5 100644 --- a/src/display/node_stream.js +++ b/src/display/node_stream.js @@ -163,12 +163,11 @@ class BaseFullReader { return this.read(); } this._loaded += chunk.length; - if (this.onProgress) { - this.onProgress({ - loaded: this._loaded, - total: this._contentLength, - }); - } + this.onProgress?.({ + loaded: this._loaded, + total: this._contentLength, + }); + // Ensure that `read()` method returns ArrayBuffer. const buffer = new Uint8Array(chunk).buffer; return { value: buffer, done: false }; diff --git a/src/display/transport_stream.js b/src/display/transport_stream.js index e731593e9..7cdee5407 100644 --- a/src/display/transport_stream.js +++ b/src/display/transport_stream.js @@ -92,15 +92,12 @@ class PDFDataTransportStream { _onProgress(evt) { if (evt.total === undefined) { // Reporting to first range reader, if it exists. - const firstReader = this._rangeReaders[0]; - if (firstReader?.onProgress) { - firstReader.onProgress({ loaded: evt.loaded }); - } + this._rangeReaders[0]?.onProgress?.({ loaded: evt.loaded }); } else { - const fullReader = this._fullRequestReader; - if (fullReader?.onProgress) { - fullReader.onProgress({ loaded: evt.loaded, total: evt.total }); - } + this._fullRequestReader?.onProgress?.({ + loaded: evt.loaded, + total: evt.total, + }); } }