Stream.call(this);
}
+// Otherwise people can pipe Writable streams, which is just wrong.
+Writable.prototype.pipe = function() {
+ this.emit('error', new Error('Cannot pipe. Not readable.'));
+};
+
// Override this method or _write(chunk, cb)
Writable.prototype.write = function(chunk, encoding, cb) {
var state = this._writableState;
var common = require('../common.js');
var W = require('_stream_writable');
+var D = require('_stream_duplex');
var assert = require('assert');
var util = require('util');
var buf = new Buffer(hex, 'hex');
tw.write(buf, 'binary');
});
+
+test('writables are not pipable', function(t) {
+ var w = new W();
+ w._write = function() {};
+ var gotError = false;
+ w.on('error', function(er) {
+ gotError = true;
+ });
+ w.pipe(process.stdout);
+ assert(gotError);
+ t.end();
+});
+
+test('duplexes are pipable', function(t) {
+ var d = new D();
+ d._read = function() {};
+ d._write = function() {};
+ var gotError = false;
+ d.on('error', function(er) {
+ gotError = true;
+ });
+ d.pipe(process.stdout);
+ assert(!gotError);
+ t.end();
+});