mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #17706 from Snuffleupagus/Node-Fetch-API
[api-minor] Use the Fetch API, when supported, to load PDF documents in Node.js environments
This commit is contained in:
commit
0022310b9c
6 changed files with 123 additions and 54 deletions
|
@ -419,7 +419,16 @@ function getDocument(src) {
|
|||
PDFJSDev.test("GENERIC") &&
|
||||
isNodeJS
|
||||
) {
|
||||
return new PDFNodeStream(params);
|
||||
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)
|
||||
|
@ -762,6 +771,9 @@ class PDFDocumentProxy {
|
|||
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||
// For testing purposes.
|
||||
Object.defineProperty(this, "getNetworkStreamName", {
|
||||
value: () => this._transport.getNetworkStreamName(),
|
||||
});
|
||||
Object.defineProperty(this, "getXFADatasets", {
|
||||
value: () => this._transport.getXFADatasets(),
|
||||
});
|
||||
|
@ -2359,6 +2371,9 @@ class WorkerTransport {
|
|||
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||
// For testing purposes.
|
||||
Object.defineProperty(this, "getNetworkStreamName", {
|
||||
value: () => networkStream?.constructor?.name || null,
|
||||
});
|
||||
Object.defineProperty(this, "getXFADatasets", {
|
||||
value: () =>
|
||||
this.messageHandler.sendWithPromise("GetXFADatasets", null),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue