Permalink
Browse files

writable.write() can take an encoding argument

  • Loading branch information...
isaacs committed Oct 2, 2012
1 parent f26c3ec commit abe4b73f4a284d3588b7936eb9be4265b701345f
Showing with 6 additions and 3 deletions.
  1. +6 −3 writable.js
View
@@ -39,13 +39,16 @@ function Writable(options) {
// Override this method for sync streams
// override the _write(chunk, cb) method for async streams
-Writable.prototype.write = function(chunk) {
+Writable.prototype.write = function(chunk, encoding) {
var state = this._writableState;
if (state.ended) {
this.emit('error', new Error('write after end'));
return;
}
+ if (typeof chunk === 'string' && encoding)
+ chunk = new Buffer(chunk, encoding);
+
var ret = state.length >= state.highWaterMark;
if (ret === false)
state.needDrain = true;
@@ -95,11 +98,11 @@ Writable.prototype._write = function(chunk, cb) {
process.nextTick(cb.bind(this, new Error('not implemented')));
};
-Writable.prototype.end = function(chunk) {
+Writable.prototype.end = function(chunk, encoding) {
var state = this._writableState;
state.ending = true;
if (chunk)
- this.write(chunk);
+ this.write(chunk, encoding);
else if (state.length === 0)
this.emit('finish');
state.ended = true;

0 comments on commit abe4b73

Please sign in to comment.