diff --git a/src/display/node_stream.js b/src/display/node_stream.js index df26d5c73..4c028a5c5 100644 --- a/src/display/node_stream.js +++ b/src/display/node_stream.js @@ -424,21 +424,22 @@ class PDFNodeStreamFsFullReader extends BaseFullReader { path = path.replace(/^\//, ""); } - fs.lstat(path, (error, stat) => { - if (error) { + fs.promises.lstat(path).then( + stat => { + // Setting right content length. + this._contentLength = stat.size; + + this._setReadableStream(fs.createReadStream(path)); + this._headersCapability.resolve(); + }, + error => { if (error.code === "ENOENT") { error = new MissingPDFException(`Missing PDF "${path}".`); } this._storedError = error; this._headersCapability.reject(error); - return; } - // Setting right content length. - this._contentLength = stat.size; - - this._setReadableStream(fs.createReadStream(path)); - this._headersCapability.resolve(); - }); + ); } } diff --git a/src/display/node_utils.js b/src/display/node_utils.js index eb1219e8e..ff7afeb18 100644 --- a/src/display/node_utils.js +++ b/src/display/node_utils.js @@ -71,15 +71,7 @@ if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("SKIP_BABEL")) { } const fetchData = function (url) { - return new Promise((resolve, reject) => { - fs.readFile(url, (error, data) => { - if (error || !data) { - reject(new Error(error)); - return; - } - resolve(new Uint8Array(data)); - }); - }); + return fs.promises.readFile(url).then(data => new Uint8Array(data)); }; class NodeFilterFactory extends BaseFilterFactory {}