Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: unecessary argument validation #29043

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
ronag marked this conversation as resolved.
Show resolved Hide resolved