summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2019-08-08 11:18:39 +0200
committerRich Trott <rtrott@gmail.com>2019-09-22 16:23:02 -0700
commit95d6ad67bfc9ef3e2f4705c81c88e32c5b1cea51 (patch)
treef376f48d677cd9eb6b4806d7064844416dbaf8a6
parenta861b84d5d260d580243741b8e2f1c2b7330a6a2 (diff)
downloadandroid-node-v8-95d6ad67bfc9ef3e2f4705c81c88e32c5b1cea51.tar.gz
android-node-v8-95d6ad67bfc9ef3e2f4705c81c88e32c5b1cea51.tar.bz2
android-node-v8-95d6ad67bfc9ef3e2f4705c81c88e32c5b1cea51.zip
fs: remove unnecessary argument check
Writable already assures that only Buffer's are passed to _write. Also this is not the "correct" way to handle errors inside _write. PR-URL: https://github.com/nodejs/node/pull/29043 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
-rw-r--r--lib/internal/fs/streams.js9
-rw-r--r--test/parallel/test-fs-write-stream.js13
2 files changed, 10 insertions, 12 deletions
diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js
index b0c4224893..110ad11493 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');
@@ -235,6 +234,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;
@@ -295,11 +297,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 5e75f4a0b3..18374f44eb 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();
}