Merge pull request #20840 from Snuffleupagus/getDocument-rm-length

[api-minor] Remove the `length` parameter from `getDocument`
This commit is contained in:
Tim van der Meij 2026-03-15 11:48:02 +01:00 committed by GitHub
commit 315491dd32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 11 additions and 40 deletions

View File

@ -196,7 +196,6 @@ class WorkerMessageHandler {
password, password,
disableAutoFetch, disableAutoFetch,
rangeChunkSize, rangeChunkSize,
length,
docBaseUrl, docBaseUrl,
enableXfa, enableXfa,
evaluatorOptions, evaluatorOptions,
@ -209,7 +208,7 @@ class WorkerMessageHandler {
enableXfa, enableXfa,
evaluatorOptions, evaluatorOptions,
handler, handler,
length, length: 0,
password, password,
rangeChunkSize, rangeChunkSize,
}; };
@ -287,14 +286,9 @@ class WorkerMessageHandler {
} }
if (!newPdfManager) { if (!newPdfManager) {
const pdfFile = arrayBuffersToBytes(cachedChunks); pdfManagerArgs.source = arrayBuffersToBytes(cachedChunks);
cachedChunks = null; cachedChunks = null;
if (length && pdfFile.length !== length) {
warn("reported HTTP length is different from actual");
}
pdfManagerArgs.source = pdfFile;
newPdfManager = new LocalPdfManager(pdfManagerArgs); newPdfManager = new LocalPdfManager(pdfManagerArgs);
resolve(newPdfManager); resolve(newPdfManager);
} }

View File

@ -124,8 +124,6 @@ const RENDERING_CANCELLED_TIMEOUT = 100; // ms
* cross-site Access-Control requests should be made using credentials such * cross-site Access-Control requests should be made using credentials such
* as cookies or authorization headers. The default is `false`. * as cookies or authorization headers. The default is `false`.
* @property {string} [password] - For decrypting password-protected PDFs. * @property {string} [password] - For decrypting password-protected PDFs.
* @property {number} [length] - The PDF file length. It's used for progress
* reports and range requests operations.
* @property {PDFDataRangeTransport} [range] - Allows for using a custom range * @property {PDFDataRangeTransport} [range] - Allows for using a custom range
* transport implementation. * transport implementation.
* @property {number} [rangeChunkSize] - Specify maximum number of bytes fetched * @property {number} [rangeChunkSize] - Specify maximum number of bytes fetched
@ -353,7 +351,6 @@ function getDocument(src = {}) {
const pagesMapper = src.pagesMapper || new PagesMapper(); const pagesMapper = src.pagesMapper || new PagesMapper();
// Parameters whose default values depend on other parameters. // Parameters whose default values depend on other parameters.
const length = rangeTransport ? rangeTransport.length : (src.length ?? NaN);
const useSystemFonts = const useSystemFonts =
typeof src.useSystemFonts === "boolean" typeof src.useSystemFonts === "boolean"
? src.useSystemFonts ? src.useSystemFonts
@ -425,7 +422,6 @@ function getDocument(src = {}) {
password, password,
disableAutoFetch, disableAutoFetch,
rangeChunkSize, rangeChunkSize,
length,
docBaseUrl, docBaseUrl,
enableXfa, enableXfa,
evaluatorOptions: { evaluatorOptions: {
@ -497,7 +493,6 @@ function getDocument(src = {}) {
networkStream = new NetworkStream({ networkStream = new NetworkStream({
url, url,
length,
httpHeaders, httpHeaders,
withCredentials, withCredentials,
rangeChunkSize, rangeChunkSize,

View File

@ -86,15 +86,12 @@ class PDFFetchStreamReader extends BasePDFStreamReader {
const { const {
disableRange, disableRange,
disableStream, disableStream,
length,
rangeChunkSize, rangeChunkSize,
url, url,
withCredentials, withCredentials,
} = stream._source; } = stream._source;
this._contentLength = length;
this._isStreamingSupported = !disableStream; this._isStreamingSupported = !disableStream;
this._isRangeSupported = !disableRange;
// Always create a copy of the headers. // Always create a copy of the headers.
const headers = new Headers(stream.headers); const headers = new Headers(stream.headers);
@ -114,10 +111,8 @@ class PDFFetchStreamReader extends BasePDFStreamReader {
rangeChunkSize, rangeChunkSize,
disableRange, disableRange,
}); });
this._contentLength = contentLength;
this._isRangeSupported = isRangeSupported; this._isRangeSupported = isRangeSupported;
// Setting right content length.
this._contentLength = contentLength || this._contentLength;
this._filename = extractFilenameFromHeader(responseHeaders); this._filename = extractFilenameFromHeader(responseHeaders);

View File

@ -187,9 +187,6 @@ class PDFNetworkStreamReader extends BasePDFStreamReader {
constructor(stream) { constructor(stream) {
super(stream); super(stream);
const { length } = stream._source;
this._contentLength = length;
// Note that `XMLHttpRequest` doesn't support streaming, and range requests // Note that `XMLHttpRequest` doesn't support streaming, and range requests
// will be enabled (if supported) in `this.#onHeadersReceived` below. // will be enabled (if supported) in `this.#onHeadersReceived` below.
@ -229,12 +226,8 @@ class PDFNetworkStreamReader extends BasePDFStreamReader {
rangeChunkSize, rangeChunkSize,
disableRange, disableRange,
}); });
this._contentLength = contentLength;
if (isRangeSupported) { this._isRangeSupported = isRangeSupported;
this._isRangeSupported = true;
}
// Setting right content length.
this._contentLength = contentLength || this._contentLength;
this._filename = extractFilenameFromHeader(responseHeaders); this._filename = extractFilenameFromHeader(responseHeaders);

View File

@ -50,7 +50,7 @@ function validateRangeRequestCapabilities({
); );
} }
const rv = { const rv = {
contentLength: undefined, contentLength: 0,
isRangeSupported: false, isRangeSupported: false,
}; };

View File

@ -62,12 +62,9 @@ class PDFNodeStreamReader extends BasePDFStreamReader {
constructor(stream) { constructor(stream) {
super(stream); super(stream);
const { disableRange, disableStream, length, rangeChunkSize, url } = const { disableRange, disableStream, rangeChunkSize, url } = stream._source;
stream._source;
this._contentLength = length;
this._isStreamingSupported = !disableStream; this._isStreamingSupported = !disableStream;
this._isRangeSupported = !disableRange;
const fs = process.getBuiltinModule("fs"); const fs = process.getBuiltinModule("fs");
fs.promises fs.promises
@ -79,13 +76,10 @@ class PDFNodeStreamReader extends BasePDFStreamReader {
this._reader = readableStream.getReader(); this._reader = readableStream.getReader();
const { size } = stat; const { size } = stat;
if (size <= 2 * rangeChunkSize) {
// The file size is smaller than the size of two chunks, so it doesn't
// make any sense to abort the request and retry with a range request.
this._isRangeSupported = false;
}
// Setting right content length.
this._contentLength = size; this._contentLength = size;
// When the file size is smaller than the size of two chunks, it doesn't
// make any sense to abort the request and retry with a range request.
this._isRangeSupported = !disableRange && size > 2 * rangeChunkSize;
// We need to stop reading when range is supported and streaming is // We need to stop reading when range is supported and streaming is
// disabled. // disabled.

View File

@ -153,7 +153,7 @@ describe("network_utils", function () {
}) })
).toEqual({ ).toEqual({
isRangeSupported: false, isRangeSupported: false,
contentLength: undefined, contentLength: 0,
}); });
}); });