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,
disableAutoFetch,
rangeChunkSize,
length,
docBaseUrl,
enableXfa,
evaluatorOptions,
@ -209,7 +208,7 @@ class WorkerMessageHandler {
enableXfa,
evaluatorOptions,
handler,
length,
length: 0,
password,
rangeChunkSize,
};
@ -287,14 +286,9 @@ class WorkerMessageHandler {
}
if (!newPdfManager) {
const pdfFile = arrayBuffersToBytes(cachedChunks);
pdfManagerArgs.source = arrayBuffersToBytes(cachedChunks);
cachedChunks = null;
if (length && pdfFile.length !== length) {
warn("reported HTTP length is different from actual");
}
pdfManagerArgs.source = pdfFile;
newPdfManager = new LocalPdfManager(pdfManagerArgs);
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
* as cookies or authorization headers. The default is `false`.
* @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
* transport implementation.
* @property {number} [rangeChunkSize] - Specify maximum number of bytes fetched
@ -353,7 +351,6 @@ function getDocument(src = {}) {
const pagesMapper = src.pagesMapper || new PagesMapper();
// Parameters whose default values depend on other parameters.
const length = rangeTransport ? rangeTransport.length : (src.length ?? NaN);
const useSystemFonts =
typeof src.useSystemFonts === "boolean"
? src.useSystemFonts
@ -425,7 +422,6 @@ function getDocument(src = {}) {
password,
disableAutoFetch,
rangeChunkSize,
length,
docBaseUrl,
enableXfa,
evaluatorOptions: {
@ -497,7 +493,6 @@ function getDocument(src = {}) {
networkStream = new NetworkStream({
url,
length,
httpHeaders,
withCredentials,
rangeChunkSize,

View File

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

View File

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

View File

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

View File

@ -62,12 +62,9 @@ class PDFNodeStreamReader extends BasePDFStreamReader {
constructor(stream) {
super(stream);
const { disableRange, disableStream, length, rangeChunkSize, url } =
stream._source;
const { disableRange, disableStream, rangeChunkSize, url } = stream._source;
this._contentLength = length;
this._isStreamingSupported = !disableStream;
this._isRangeSupported = !disableRange;
const fs = process.getBuiltinModule("fs");
fs.promises
@ -79,13 +76,10 @@ class PDFNodeStreamReader extends BasePDFStreamReader {
this._reader = readableStream.getReader();
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;
// 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
// disabled.

View File

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