Skip to content

Commit

Permalink
Merge pull request #18756 from Snuffleupagus/api-NetworkStream
Browse files Browse the repository at this point in the history
Simplify the code that picks the appropriate NetworkStream-implementation
  • Loading branch information
timvandermeij authored Sep 17, 2024
2 parents f68310b + f77a29d commit a58cd68
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a58cd68

Please sign in to comment.