Skip to content

Commit

Permalink
Merge pull request #15485 from Snuffleupagus/more-optional-chaining-2
Browse files Browse the repository at this point in the history
Use more optional chaining in the code-base (PR 15398 follow-up)
  • Loading branch information
timvandermeij authored Sep 24, 2022
2 parents 7404091 + 9f63796 commit 10f6a01
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
11 changes: 5 additions & 6 deletions src/display/fetch_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down
11 changes: 5 additions & 6 deletions src/display/node_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
13 changes: 5 additions & 8 deletions src/display/transport_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}

Expand Down

0 comments on commit 10f6a01

Please sign in to comment.