mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-09 03:31:01 +02:00
Merge pull request #20634 from Snuffleupagus/progressiveDone-resolve-requests
Ensure that pending requests are resolved when calling `PDFDataTransportStreamReader.prototype.progressiveDone`
This commit is contained in:
commit
2b95a8eb38
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AbortException, assert, warn } from "../shared/util.js";
|
||||
import { AbortException, assert } from "../shared/util.js";
|
||||
import {
|
||||
BasePDFStream,
|
||||
BasePDFStreamRangeReader,
|
||||
@ -58,8 +58,7 @@ function getArrayBuffer(val) {
|
||||
if (val instanceof ArrayBuffer) {
|
||||
return val;
|
||||
}
|
||||
warn(`getArrayBuffer - unexpected data format: ${val}`);
|
||||
return new Uint8Array(val).buffer;
|
||||
throw new Error(`getArrayBuffer - unexpected data: ${val}`);
|
||||
}
|
||||
|
||||
class PDFFetchStream extends BasePDFStream {
|
||||
@ -194,4 +193,4 @@ class PDFFetchStreamRangeReader extends BasePDFStreamRangeReader {
|
||||
}
|
||||
}
|
||||
|
||||
export { PDFFetchStream };
|
||||
export { getArrayBuffer, PDFFetchStream };
|
||||
|
||||
@ -27,6 +27,7 @@ import {
|
||||
getResponseOrigin,
|
||||
validateRangeRequestCapabilities,
|
||||
} from "./network_utils.js";
|
||||
import { endRequests } from "./transport_stream.js";
|
||||
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||
throw new Error(
|
||||
@ -174,6 +175,8 @@ class PDFNetworkStream extends BasePDFStream {
|
||||
}
|
||||
|
||||
class PDFNetworkStreamReader extends BasePDFStreamReader {
|
||||
#endRequests = endRequests.bind(this);
|
||||
|
||||
_cachedChunks = [];
|
||||
|
||||
_done = false;
|
||||
@ -254,13 +257,9 @@ class PDFNetworkStreamReader extends BasePDFStreamReader {
|
||||
this._cachedChunks.push(chunk);
|
||||
}
|
||||
this._done = true;
|
||||
if (this._cachedChunks.length > 0) {
|
||||
return;
|
||||
if (this._cachedChunks.length === 0) {
|
||||
this.#endRequests();
|
||||
}
|
||||
for (const capability of this._requests) {
|
||||
capability.resolve({ value: undefined, done: true });
|
||||
}
|
||||
this._requests.length = 0;
|
||||
}
|
||||
|
||||
#onError(status) {
|
||||
@ -301,10 +300,7 @@ class PDFNetworkStreamReader extends BasePDFStreamReader {
|
||||
cancel(reason) {
|
||||
this._done = true;
|
||||
this._headersCapability.reject(reason);
|
||||
for (const capability of this._requests) {
|
||||
capability.resolve({ value: undefined, done: true });
|
||||
}
|
||||
this._requests.length = 0;
|
||||
this.#endRequests();
|
||||
|
||||
this._stream._abortRequest(this._fullRequestXhr);
|
||||
this._fullRequestXhr = null;
|
||||
@ -312,6 +308,8 @@ class PDFNetworkStreamReader extends BasePDFStreamReader {
|
||||
}
|
||||
|
||||
class PDFNetworkStreamRangeReader extends BasePDFStreamRangeReader {
|
||||
#endRequests = endRequests.bind(this);
|
||||
|
||||
onClosed = null;
|
||||
|
||||
_done = false;
|
||||
@ -353,10 +351,7 @@ class PDFNetworkStreamRangeReader extends BasePDFStreamRangeReader {
|
||||
this._queuedChunk = chunk;
|
||||
}
|
||||
this._done = true;
|
||||
for (const capability of this._requests) {
|
||||
capability.resolve({ value: undefined, done: true });
|
||||
}
|
||||
this._requests.length = 0;
|
||||
this.#endRequests();
|
||||
this.onClosed?.();
|
||||
}
|
||||
|
||||
@ -388,10 +383,7 @@ class PDFNetworkStreamRangeReader extends BasePDFStreamRangeReader {
|
||||
|
||||
cancel(reason) {
|
||||
this._done = true;
|
||||
for (const capability of this._requests) {
|
||||
capability.resolve({ value: undefined, done: true });
|
||||
}
|
||||
this._requests.length = 0;
|
||||
this.#endRequests();
|
||||
|
||||
this._stream._abortRequest(this._requestXhr);
|
||||
this.onClosed?.();
|
||||
|
||||
@ -14,13 +14,14 @@
|
||||
*/
|
||||
/* globals process */
|
||||
|
||||
import { AbortException, assert, warn } from "../shared/util.js";
|
||||
import { AbortException, assert } from "../shared/util.js";
|
||||
import {
|
||||
BasePDFStream,
|
||||
BasePDFStreamRangeReader,
|
||||
BasePDFStreamReader,
|
||||
} from "../shared/base_pdf_stream.js";
|
||||
import { createResponseError } from "./network_utils.js";
|
||||
import { getArrayBuffer } from "./fetch_stream.js";
|
||||
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||
throw new Error(
|
||||
@ -44,17 +45,6 @@ function getReadableStream(readStream) {
|
||||
return polyfill.makeDefaultReadableStreamFromNodeReadable(readStream);
|
||||
}
|
||||
|
||||
function getArrayBuffer(val) {
|
||||
if (val instanceof Uint8Array) {
|
||||
return val.buffer;
|
||||
}
|
||||
if (val instanceof ArrayBuffer) {
|
||||
return val;
|
||||
}
|
||||
warn(`getArrayBuffer - unexpected data format: ${val}`);
|
||||
return new Uint8Array(val).buffer;
|
||||
}
|
||||
|
||||
class PDFNodeStream extends BasePDFStream {
|
||||
constructor(source) {
|
||||
super(source, PDFNodeStreamReader, PDFNodeStreamRangeReader);
|
||||
|
||||
@ -29,6 +29,13 @@ function getArrayBuffer(val) {
|
||||
: new Uint8Array(val).buffer;
|
||||
}
|
||||
|
||||
function endRequests() {
|
||||
for (const capability of this._requests) {
|
||||
capability.resolve({ value: undefined, done: true });
|
||||
}
|
||||
this._requests.length = 0;
|
||||
}
|
||||
|
||||
class PDFDataTransportStream extends BasePDFStream {
|
||||
_progressiveDone = false;
|
||||
|
||||
@ -112,6 +119,8 @@ class PDFDataTransportStream extends BasePDFStream {
|
||||
}
|
||||
|
||||
class PDFDataTransportStreamReader extends BasePDFStreamReader {
|
||||
#endRequests = endRequests.bind(this);
|
||||
|
||||
_done = false;
|
||||
|
||||
_queuedChunks = null;
|
||||
@ -179,18 +188,21 @@ class PDFDataTransportStreamReader extends BasePDFStreamReader {
|
||||
|
||||
cancel(reason) {
|
||||
this._done = true;
|
||||
for (const capability of this._requests) {
|
||||
capability.resolve({ value: undefined, done: true });
|
||||
}
|
||||
this._requests.length = 0;
|
||||
this.#endRequests();
|
||||
}
|
||||
|
||||
progressiveDone() {
|
||||
this._done ||= true;
|
||||
|
||||
if (this._queuedChunks.length === 0) {
|
||||
this.#endRequests();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PDFDataTransportStreamRangeReader extends BasePDFStreamRangeReader {
|
||||
#endRequests = endRequests.bind(this);
|
||||
|
||||
onDone = null;
|
||||
|
||||
_begin = -1;
|
||||
@ -213,13 +225,10 @@ class PDFDataTransportStreamRangeReader extends BasePDFStreamRangeReader {
|
||||
if (this._requests.length === 0) {
|
||||
this._queuedChunk = chunk;
|
||||
} else {
|
||||
const firstCapability = this._requests.shift();
|
||||
firstCapability.resolve({ value: chunk, done: false });
|
||||
const capability = this._requests.shift();
|
||||
capability.resolve({ value: chunk, done: false });
|
||||
|
||||
for (const capability of this._requests) {
|
||||
capability.resolve({ value: undefined, done: true });
|
||||
}
|
||||
this._requests.length = 0;
|
||||
this.#endRequests();
|
||||
}
|
||||
this._done = true;
|
||||
this.onDone?.();
|
||||
@ -241,12 +250,9 @@ class PDFDataTransportStreamRangeReader extends BasePDFStreamRangeReader {
|
||||
|
||||
cancel(reason) {
|
||||
this._done = true;
|
||||
for (const capability of this._requests) {
|
||||
capability.resolve({ value: undefined, done: true });
|
||||
}
|
||||
this._requests.length = 0;
|
||||
this.#endRequests();
|
||||
this.onDone?.();
|
||||
}
|
||||
}
|
||||
|
||||
export { PDFDataTransportStream };
|
||||
export { endRequests, PDFDataTransportStream };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user