Merge pull request #17714 from Snuffleupagus/Node-fs-promise

Use `fs/promises` in the Node.js-specific code in the `src/`-folder
This commit is contained in:
Jonas Jenwald 2024-03-12 18:09:33 +01:00 committed by GitHub
commit e650b95253
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 18 deletions

View File

@ -424,21 +424,22 @@ class PDFNodeStreamFsFullReader extends BaseFullReader {
path = path.replace(/^\//, ""); path = path.replace(/^\//, "");
} }
fs.lstat(path, (error, stat) => { fs.promises.lstat(path).then(
if (error) { stat => {
// Setting right content length.
this._contentLength = stat.size;
this._setReadableStream(fs.createReadStream(path));
this._headersCapability.resolve();
},
error => {
if (error.code === "ENOENT") { if (error.code === "ENOENT") {
error = new MissingPDFException(`Missing PDF "${path}".`); error = new MissingPDFException(`Missing PDF "${path}".`);
} }
this._storedError = error; this._storedError = error;
this._headersCapability.reject(error); this._headersCapability.reject(error);
return;
} }
// Setting right content length. );
this._contentLength = stat.size;
this._setReadableStream(fs.createReadStream(path));
this._headersCapability.resolve();
});
} }
} }

View File

@ -71,15 +71,7 @@ if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("SKIP_BABEL")) {
} }
const fetchData = function (url) { const fetchData = function (url) {
return new Promise((resolve, reject) => { return fs.promises.readFile(url).then(data => new Uint8Array(data));
fs.readFile(url, (error, data) => {
if (error || !data) {
reject(new Error(error));
return;
}
resolve(new Uint8Array(data));
});
});
}; };
class NodeFilterFactory extends BaseFilterFactory {} class NodeFilterFactory extends BaseFilterFactory {}