diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index d51fbb1b580113..d923e8ab6b23fa 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -3,7 +3,6 @@ const { Math, Object } = primordials; const { - ERR_INVALID_ARG_TYPE, ERR_OUT_OF_RANGE } = require('internal/errors').codes; const { validateNumber } = require('internal/validators'); @@ -238,6 +237,9 @@ function WriteStream(path, options) { options = copyObject(getOptions(options, {})); + // Only buffers are supported. + options.decodeStrings = true; + // For backwards compat do not emit close on destroy. if (options.emitClose === undefined) { options.emitClose = false; @@ -298,11 +300,6 @@ WriteStream.prototype.open = function() { WriteStream.prototype._write = function(data, encoding, cb) { - if (!(data instanceof Buffer)) { - const err = new ERR_INVALID_ARG_TYPE('data', 'Buffer', data); - return this.emit('error', err); - } - if (typeof this.fd !== 'number') { return this.once('open', function() { this._write(data, encoding, cb); diff --git a/test/parallel/test-fs-write-stream.js b/test/parallel/test-fs-write-stream.js index 5e75f4a0b306d2..18374f44ebcdad 100644 --- a/test/parallel/test-fs-write-stream.js +++ b/test/parallel/test-fs-write-stream.js @@ -56,12 +56,13 @@ tmpdir.refresh(); // Throws if data is not of type Buffer. { const stream = fs.createWriteStream(file); - common.expectsError(() => { - stream._write(42, null, function() {}); - }, { + stream.on('error', common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "data" argument must be of type Buffer. Received type number' - }); + type: TypeError + })); + stream.write(42, null, common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError + })); stream.destroy(); }