Skip to content

Commit

Permalink
fs: remove unnecessary argument check
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 26, 2019
1 parent 66043e1 commit 71ad3c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
9 changes: 3 additions & 6 deletions lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 1 addition & 14 deletions test/parallel/test-fs-write-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
}

0 comments on commit 71ad3c6

Please sign in to comment.