diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 9843064efbc472..c58c0698d30cf0 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -116,7 +116,7 @@ class FileHandle { return writeFile(this, data, options); } - close() { + close = () => { return this[kHandle].close(); } } @@ -411,7 +411,7 @@ async function lchmod(path, mode) { throw new ERR_METHOD_NOT_IMPLEMENTED('lchmod()'); const fd = await open(path, O_WRONLY | O_SYMLINK); - return fchmod(fd, mode).finally(fd.close.bind(fd)); + return fchmod(fd, mode).finally(fd.close); } async function lchown(path, uid, gid) { @@ -476,7 +476,7 @@ async function writeFile(path, data, options) { return writeFileHandle(path, data, options); const fd = await open(path, flag, options.mode); - return writeFileHandle(fd, data, options).finally(fd.close.bind(fd)); + return writeFileHandle(fd, data, options).finally(fd.close); } async function appendFile(path, data, options) { @@ -494,7 +494,7 @@ async function readFile(path, options) { return readFileHandle(path, options); const fd = await open(path, flag, 0o666); - return readFileHandle(fd, options).finally(fd.close.bind(fd)); + return readFileHandle(fd, options).finally(fd.close); } module.exports = { diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index 1ef52333a8bda9..4d2fc757018156 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -372,7 +372,7 @@ WriteStream.prototype.close = function(cb) { // If we are not autoClosing, we should call // destroy on 'finish'. if (!this.autoClose) { - this.on('finish', this.destroy.bind(this)); + this.on('finish', this.destroy); } // We use end() instead of destroy() because of