Merge pull request #18756 from Snuffleupagus/api-NetworkStream
Simplify the code that picks the appropriate NetworkStream-implementation
This commit is contained in:
commit
a58cd6851e
@ -413,34 +413,34 @@ function getDocument(src = {}) {
|
|||||||
});
|
});
|
||||||
} else if (!data) {
|
} else if (!data) {
|
||||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||||
throw new Error("Not implemented: createPDFNetworkStream");
|
throw new Error("Not implemented: NetworkStream");
|
||||||
}
|
}
|
||||||
if (!url) {
|
if (!url) {
|
||||||
throw new Error("getDocument - no `url` parameter provided.");
|
throw new Error("getDocument - no `url` parameter provided.");
|
||||||
}
|
}
|
||||||
const createPDFNetworkStream = params => {
|
let NetworkStream;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof PDFJSDev !== "undefined" &&
|
typeof PDFJSDev !== "undefined" &&
|
||||||
PDFJSDev.test("GENERIC") &&
|
PDFJSDev.test("GENERIC") &&
|
||||||
isNodeJS
|
isNodeJS
|
||||||
) {
|
) {
|
||||||
const isFetchSupported = function () {
|
const isFetchSupported =
|
||||||
return (
|
|
||||||
typeof fetch !== "undefined" &&
|
typeof fetch !== "undefined" &&
|
||||||
typeof Response !== "undefined" &&
|
typeof Response !== "undefined" &&
|
||||||
"body" in Response.prototype
|
"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);
|
|
||||||
};
|
|
||||||
|
|
||||||
networkStream = createPDFNetworkStream({
|
NetworkStream =
|
||||||
|
isFetchSupported && isValidFetchUrl(url)
|
||||||
|
? PDFFetchStream
|
||||||
|
: PDFNodeStream;
|
||||||
|
} else {
|
||||||
|
NetworkStream = isValidFetchUrl(url)
|
||||||
|
? PDFFetchStream
|
||||||
|
: PDFNetworkStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
networkStream = new NetworkStream({
|
||||||
url,
|
url,
|
||||||
length,
|
length,
|
||||||
httpHeaders,
|
httpHeaders,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user