diff --git a/src/core/worker.js b/src/core/worker.js index 44e438a77..4aef9e996 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -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); } diff --git a/src/display/api.js b/src/display/api.js index 23c994276..c8805b7bf 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -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, diff --git a/src/display/fetch_stream.js b/src/display/fetch_stream.js index 82270d7df..179f0a329 100644 --- a/src/display/fetch_stream.js +++ b/src/display/fetch_stream.js @@ -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); diff --git a/src/display/network.js b/src/display/network.js index 86548c41f..a4d94be88 100644 --- a/src/display/network.js +++ b/src/display/network.js @@ -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); diff --git a/src/display/network_utils.js b/src/display/network_utils.js index 67b2eb61a..bd2779706 100644 --- a/src/display/network_utils.js +++ b/src/display/network_utils.js @@ -50,7 +50,7 @@ function validateRangeRequestCapabilities({ ); } const rv = { - contentLength: undefined, + contentLength: 0, isRangeSupported: false, }; diff --git a/src/display/node_stream.js b/src/display/node_stream.js index 0d57ee789..0b4c9454e 100644 --- a/src/display/node_stream.js +++ b/src/display/node_stream.js @@ -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. diff --git a/test/unit/network_utils_spec.js b/test/unit/network_utils_spec.js index 7890fcfc6..89d20f181 100644 --- a/test/unit/network_utils_spec.js +++ b/test/unit/network_utils_spec.js @@ -153,7 +153,7 @@ describe("network_utils", function () { }) ).toEqual({ isRangeSupported: false, - contentLength: undefined, + contentLength: 0, }); });