Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the code that picks the appropriate NetworkStream-implementation #18756

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 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 => {
let NetworkStream;

if (
typeof PDFJSDev !== "undefined" &&
PDFJSDev.test("GENERIC") &&
isNodeJS
) {
const isFetchSupported = function () {
return (
const isFetchSupported =
typeof fetch !== "undefined" &&
typeof Response !== "undefined" &&
"body" in Response.prototype
);
};
return isFetchSupported() && isValidFetchUrl(params.url)
? new PDFFetchStream(params)
: new PDFNodeStream(params);
"body" in Response.prototype;

NetworkStream =
isFetchSupported && isValidFetchUrl(url)
? PDFFetchStream
: PDFNodeStream;
} else {
NetworkStream = isValidFetchUrl(url)
? PDFFetchStream
: PDFNetworkStream;
}
return isValidFetchUrl(params.url)
? new PDFFetchStream(params)
: new PDFNetworkStream(params);
};

networkStream = createPDFNetworkStream({
networkStream = new NetworkStream({
url,
length,
httpHeaders,
Expand Down