diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index afb88d9eb152cb..343e09d7bc271b 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -22,7 +22,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'); @@ -266,7 +266,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', {