From f77a29d6759475854d98386ab0b1546c811a29c4 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 17 Sep 2024 12:10:04 +0200 Subject: [PATCH] Simplify the code that picks the appropriate NetworkStream-implementation This code is quite old and has been moved/re-factored a few times over the years, however we can simplify this even further since we don't actually need a function to determine what NetworkStream-implementation to use. --- src/display/api.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index 571f1e677f02f..5b65e50d663df 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -413,34 +413,34 @@ function getDocument(src = {}) { }); } else if (!data) { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { - throw new Error("Not implemented: createPDFNetworkStream"); + throw new Error("Not implemented: NetworkStream"); } if (!url) { throw new Error("getDocument - no `url` parameter provided."); } - const createPDFNetworkStream = params => { - if ( - typeof PDFJSDev !== "undefined" && - PDFJSDev.test("GENERIC") && - isNodeJS - ) { - const isFetchSupported = function () { - return ( - typeof fetch !== "undefined" && - typeof Response !== "undefined" && - "body" in Response.prototype - ); - }; - return isFetchSupported() && isValidFetchUrl(params.url) - ? new PDFFetchStream(params) - : new PDFNodeStream(params); - } - return isValidFetchUrl(params.url) - ? new PDFFetchStream(params) - : new PDFNetworkStream(params); - }; + let NetworkStream; + + if ( + typeof PDFJSDev !== "undefined" && + PDFJSDev.test("GENERIC") && + isNodeJS + ) { + const isFetchSupported = + typeof fetch !== "undefined" && + typeof Response !== "undefined" && + "body" in Response.prototype; + + NetworkStream = + isFetchSupported && isValidFetchUrl(url) + ? PDFFetchStream + : PDFNodeStream; + } else { + NetworkStream = isValidFetchUrl(url) + ? PDFFetchStream + : PDFNetworkStream; + } - networkStream = createPDFNetworkStream({ + networkStream = new NetworkStream({ url, length, httpHeaders,