mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 08:38:06 +02:00
Merge pull request #18977 from Snuffleupagus/api-ReaderHeadersReady-simplify
Simplify the "ReaderHeadersReady" message-handler in the API
This commit is contained in:
commit
9870099e90
1 changed files with 19 additions and 24 deletions
|
@ -2646,32 +2646,27 @@ class WorkerTransport {
|
|||
};
|
||||
});
|
||||
|
||||
messageHandler.on("ReaderHeadersReady", data => {
|
||||
const headersCapability = Promise.withResolvers();
|
||||
const fullReader = this._fullReader;
|
||||
fullReader.headersReady.then(() => {
|
||||
// If stream or range are disabled, it's our only way to report
|
||||
// loading progress.
|
||||
if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
|
||||
if (this._lastProgress) {
|
||||
loadingTask.onProgress?.(this._lastProgress);
|
||||
}
|
||||
fullReader.onProgress = evt => {
|
||||
loadingTask.onProgress?.({
|
||||
loaded: evt.loaded,
|
||||
total: evt.total,
|
||||
});
|
||||
};
|
||||
messageHandler.on("ReaderHeadersReady", async data => {
|
||||
await this._fullReader.headersReady;
|
||||
|
||||
const { isStreamingSupported, isRangeSupported, contentLength } =
|
||||
this._fullReader;
|
||||
|
||||
// If stream or range are disabled, it's our only way to report
|
||||
// loading progress.
|
||||
if (!isStreamingSupported || !isRangeSupported) {
|
||||
if (this._lastProgress) {
|
||||
loadingTask.onProgress?.(this._lastProgress);
|
||||
}
|
||||
this._fullReader.onProgress = evt => {
|
||||
loadingTask.onProgress?.({
|
||||
loaded: evt.loaded,
|
||||
total: evt.total,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
headersCapability.resolve({
|
||||
isStreamingSupported: fullReader.isStreamingSupported,
|
||||
isRangeSupported: fullReader.isRangeSupported,
|
||||
contentLength: fullReader.contentLength,
|
||||
});
|
||||
}, headersCapability.reject);
|
||||
|
||||
return headersCapability.promise;
|
||||
return { isStreamingSupported, isRangeSupported, contentLength };
|
||||
});
|
||||
|
||||
messageHandler.on("GetRangeReader", (data, sink) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue