Skip to content

Commit 71ad3c6

Browse files
committed
fs: remove unnecessary argument check
1 parent 66043e1 commit 71ad3c6

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

lib/internal/fs/streams.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const { Math, Object } = primordials;
44

55
const {
6-
ERR_INVALID_ARG_TYPE,
76
ERR_OUT_OF_RANGE
87
} = require('internal/errors').codes;
98
const { validateNumber } = require('internal/validators');
@@ -238,6 +237,9 @@ function WriteStream(path, options) {
238237

239238
options = copyObject(getOptions(options, {}));
240239

240+
// Only buffers are supported.
241+
options.decodeStrings = true;
242+
241243
// For backwards compat do not emit close on destroy.
242244
if (options.emitClose === undefined) {
243245
options.emitClose = false;
@@ -298,11 +300,6 @@ WriteStream.prototype.open = function() {
298300

299301

300302
WriteStream.prototype._write = function(data, encoding, cb) {
301-
if (!(data instanceof Buffer)) {
302-
const err = new ERR_INVALID_ARG_TYPE('data', 'Buffer', data);
303-
return this.emit('error', err);
304-
}
305-
306303
if (typeof this.fd !== 'number') {
307304
return this.once('open', function() {
308305
this._write(data, encoding, cb);

test/parallel/test-fs-write-stream.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
const common = require('../common');
23+
require('../common');
2424
const assert = require('assert');
2525
const path = require('path');
2626
const fs = require('fs');
@@ -52,16 +52,3 @@ tmpdir.refresh();
5252
});
5353
stream.destroy();
5454
}
55-
56-
// Throws if data is not of type Buffer.
57-
{
58-
const stream = fs.createWriteStream(file);
59-
common.expectsError(() => {
60-
stream._write(42, null, function() {});
61-
}, {
62-
code: 'ERR_INVALID_ARG_TYPE',
63-
type: TypeError,
64-
message: 'The "data" argument must be of type Buffer. Received type number'
65-
});
66-
stream.destroy();
67-
}

0 commit comments

Comments
 (0)