From 71ad3c6107d3dabd674cb34cc4aa21544be1f24a Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 8 Aug 2019 11:18:39 +0200 Subject: [PATCH] fs: remove unnecessary argument check --- lib/internal/fs/streams.js | 9 +++------ test/parallel/test-fs-write-stream.js | 15 +-------------- 2 files changed, 4 insertions(+), 20 deletions(-) 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..6d263f450b6a4b 100644 --- a/test/parallel/test-fs-write-stream.js +++ b/test/parallel/test-fs-write-stream.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const path = require('path'); const fs = require('fs'); @@ -52,16 +52,3 @@ tmpdir.refresh(); }); stream.destroy(); } - -// Throws if data is not of type Buffer. -{ - const stream = fs.createWriteStream(file); - common.expectsError(() => { - stream._write(42, null, function() {}); - }, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "data" argument must be of type Buffer. Received type number' - }); - stream.destroy(); -}