summaryrefslogtreecommitdiff
path: root/lib/_stream_writable.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/_stream_writable.js')
-rw-r--r--lib/_stream_writable.js25
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js
index cada467f74..a6b02f6c2a 100644
--- a/lib/_stream_writable.js
+++ b/lib/_stream_writable.js
@@ -153,10 +153,9 @@ function writeAfterEnd(stream, state, cb) {
// how many bytes or characters.
function validChunk(stream, state, chunk, cb) {
var valid = true;
- if (!Buffer.isBuffer(chunk) &&
- 'string' !== typeof chunk &&
- chunk !== null &&
- chunk !== undefined &&
+ if (!IS_BUFFER(chunk) &&
+ !IS_STRING(chunk) &&
+ !IS_NULL_OR_UNDEFINED(chunk) &&
!state.objectMode) {
var er = new TypeError('Invalid non-string/buffer chunk');
stream.emit('error', er);
@@ -172,17 +171,17 @@ Writable.prototype.write = function(chunk, encoding, cb) {
var state = this._writableState;
var ret = false;
- if (typeof encoding === 'function') {
+ if (IS_FUNCTION(encoding)) {
cb = encoding;
encoding = null;
}
- if (Buffer.isBuffer(chunk))
+ if (IS_BUFFER(chunk))
encoding = 'buffer';
else if (!encoding)
encoding = state.defaultEncoding;
- if (typeof cb !== 'function')
+ if (!IS_FUNCTION(cb))
cb = function() {};
if (state.ended)
@@ -217,9 +216,7 @@ Writable.prototype.uncork = function() {
};
function decodeChunk(state, chunk, encoding) {
- if (!state.objectMode &&
- state.decodeStrings !== false &&
- typeof chunk === 'string') {
+ if (!state.objectMode && state.decodeStrings !== false && IS_STRING(chunk)) {
chunk = new Buffer(chunk, encoding);
}
return chunk;
@@ -230,7 +227,7 @@ function decodeChunk(state, chunk, encoding) {
// If we return false, then we need a drain event, so set that flag.
function writeOrBuffer(stream, state, chunk, encoding, cb) {
chunk = decodeChunk(state, chunk, encoding);
- if (Buffer.isBuffer(chunk))
+ if (IS_BUFFER(chunk))
encoding = 'buffer';
var len = state.objectMode ? 1 : chunk.length;
@@ -391,16 +388,16 @@ Writable.prototype._writev = null;
Writable.prototype.end = function(chunk, encoding, cb) {
var state = this._writableState;
- if (typeof chunk === 'function') {
+ if (IS_FUNCTION(chunk)) {
cb = chunk;
chunk = null;
encoding = null;
- } else if (typeof encoding === 'function') {
+ } else if (IS_FUNCTION(encoding)) {
cb = encoding;
encoding = null;
}
- if (typeof chunk !== 'undefined' && chunk !== null)
+ if (!IS_NULL_OR_UNDEFINED(chunk))
this.write(chunk, encoding);
// .end() fully uncorks