Skip to content

Commit a58cd68

Browse files
Merge pull request #18756 from Snuffleupagus/api-NetworkStream
Simplify the code that picks the appropriate NetworkStream-implementation
2 parents f68310b + f77a29d commit a58cd68

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/display/api.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -413,34 +413,34 @@ function getDocument(src = {}) {
413413
});
414414
} else if (!data) {
415415
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
416-
throw new Error("Not implemented: createPDFNetworkStream");
416+
throw new Error("Not implemented: NetworkStream");
417417
}
418418
if (!url) {
419419
throw new Error("getDocument - no `url` parameter provided.");
420420
}
421-
const createPDFNetworkStream = params => {
422-
if (
423-
typeof PDFJSDev !== "undefined" &&
424-
PDFJSDev.test("GENERIC") &&
425-
isNodeJS
426-
) {
427-
const isFetchSupported = function () {
428-
return (
429-
typeof fetch !== "undefined" &&
430-
typeof Response !== "undefined" &&
431-
"body" in Response.prototype
432-
);
433-
};
434-
return isFetchSupported() && isValidFetchUrl(params.url)
435-
? new PDFFetchStream(params)
436-
: new PDFNodeStream(params);
437-
}
438-
return isValidFetchUrl(params.url)
439-
? new PDFFetchStream(params)
440-
: new PDFNetworkStream(params);
441-
};
421+
let NetworkStream;
422+
423+
if (
424+
typeof PDFJSDev !== "undefined" &&
425+
PDFJSDev.test("GENERIC") &&
426+
isNodeJS
427+
) {
428+
const isFetchSupported =
429+
typeof fetch !== "undefined" &&
430+
typeof Response !== "undefined" &&
431+
"body" in Response.prototype;
432+
433+
NetworkStream =
434+
isFetchSupported && isValidFetchUrl(url)
435+
? PDFFetchStream
436+
: PDFNodeStream;
437+
} else {
438+
NetworkStream = isValidFetchUrl(url)
439+
? PDFFetchStream
440+
: PDFNetworkStream;
441+
}
442442

443-
networkStream = createPDFNetworkStream({
443+
networkStream = new NetworkStream({
444444
url,
445445
length,
446446
httpHeaders,

0 commit comments

Comments
 (0)