1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #18756 from Snuffleupagus/api-NetworkStream

Simplify the code that picks the appropriate NetworkStream-implementation
This commit is contained in:
Tim van der Meij 2024-09-17 19:19:19 +02:00 committed by GitHub
commit a58cd6851e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;
networkStream = createPDFNetworkStream({
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 = new NetworkStream({
url,
length,
httpHeaders,