diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index a76a8f6895c887..2f5f8948eea458 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -23,7 +23,7 @@ const { copyObject, getOptions, } = require('internal/fs/utils'); -const { Readable, Writable } = require('stream'); +const { Readable, Writable, finished } = require('stream'); const { toPathIfFileURL } = require('internal/url'); const kIoDone = Symbol('kIoDone'); const kIsPerformingIO = Symbol('kIsPerformingIO'); @@ -273,7 +273,8 @@ function closeFsStream(stream, cb, err) { } ReadStream.prototype.close = function(cb) { - this.destroy(null, cb); + if (typeof cb === 'function') finished(this, cb); + this.destroy(); }; ObjectDefineProperty(ReadStream.prototype, 'pending', {