示例#1
0
    return expect(function (res, handleError) {
      hijackResponse(res, passError(handleError, function (res) {
        delayedIdentityStream._transform = function (chunk, encoding, cb) {
          onTransformBufferLengths.push({
            hijacked: res._readableState.length,
            delayed: this._readableState.length
          })
          setTimeout(function () {
            cb(null, chunk)
          }, 3)
        }
        res.pipe(delayedIdentityStream).pipe(res)
      }), { readableOptions: streamOptions })

      res.setHeader('Content-Type', 'text/plain')

      var mockedReadStream = new stream.Stream()
      mockedReadStream.readable = true

      mockedReadStream.pipe(res)

      mockedReadStream.emit('data', 'foo 12345\n')
      mockedReadStream.emit('data', 'bar 12345\n')
      mockedReadStream.emit('data', 'baz 12345\n')
      mockedReadStream.emit('data', 'qux 12345\n')
      mockedReadStream.emit('end')
    }, 'to yield response', {
示例#2
0
        it('should create a new KLV stream and transform the incoming stream into a KLV', function(done) {
            
            var testKLV1 = new Buffer([
                  0x03, 0x2E, 0x5F, 0xAB, 0x08, 0x12, 0x2F, 0x0C, 0xEE, 0x33, 0x00, 0x01, 0x02, 0x45, 0x6D, 0xDD,
                  0x83, 0x00, 0x00, 0x05,
                  0x05, 0x04, 0x03, 0x02, 0x01]);
            var testKLV2 = new Buffer([
                  0xFF, 0x3D, 0x99, 0x23, 0x4D, 0x01, 0x02, 0x03, 0x04, 0xAD, 0xAC, 0xAB, 0xAA, 0x00, 0x00, 0x00,
                  0x82, 0x00, 0x07,
                  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07]);

            // Create a simple read stream for the testKLV bytes
            var byteStream = new stream.Stream();
            byteStream.readable = true;

            var klvStream = klv.createStream();
            byteStream.pipe(klvStream);

            var iterationCounter = 1;

            klvStream.on('key', function(key) {
                assert(key);
                assert.equal(key.length, 16);
                if (iterationCounter === 1)
                    assert.deepEqual(key, testKLV1.slice(0, 16));
                else
                    assert.deepEqual(key, testKLV2.slice(0, 16));
            });
    
            klvStream.on('value', function(value) {
                assert(value);
                assert.equal(typeof value, 'object');
                if (iterationCounter === 1) {
                    assert.equal(value.length, 5);
                    assert.deepEqual(value, testKLV1.slice(20, 25));
                }
                else {
                    assert.equal(value.length, 7);
                    assert.deepEqual(value, testKLV2.slice(19, 26));
                }
                iterationCounter++;
            });

            klvStream.on('end', function() {
                assert.equal(iterationCounter, 3);
                done();
            });

            // Emit the KLVs in multiple chopped up data events
            byteStream.emit('data', testKLV1.slice(0,10));
            byteStream.emit('data', Buffer.concat([testKLV1.slice(10), testKLV2.slice(0, 4)]));
            byteStream.emit('data', testKLV2.slice(4));
            byteStream.emit('end');
        });
示例#3
0
文件: view.js 项目: bdacode/backnode
View.prototype.pipe = function pipe(destination) {
  var view = this.render(),
    stream = new Stream;

  stream.pipe(destination);
  this.on('render', function(str) {
    stream.emit('data', view.el);
    destination.emit('data', view.el);
    stream.emit('end');
    destination.emit('end');
  });

  return destination;
};
(function testErrorListenerCatches() {
  var source = new Stream();
  var dest = new Stream();

  source.pipe(dest);

  var gotErr = null;
  source.on('error', function(err) {
    gotErr = err;
  });

  var err = new Error('This stream turned into bacon.');
  source.emit('error', err);
  assert.strictEqual(gotErr, err);
})();
示例#5
0
tape('piping to a request object with invalid uri', function(t) {
  var mybodydata = new stream.Stream()
  mybodydata.readable = true

  var r2 = request.put({
    url: '/bad-uri',
    json: true
  }, function(err, res, body) {
    t.ok(err instanceof Error)
    t.equal(err.message, 'Invalid URI "/bad-uri"')
    t.end()
  })
  mybodydata.pipe(r2)

  mybodydata.emit('data', JSON.stringify({ foo: 'bar' }))
  mybodydata.emit('end')
})
(function testErrorWithoutListenerThrows() {
  var source = new Stream();
  var dest = new Stream();

  source.pipe(dest);

  var err = new Error('This stream turned into bacon.');

  var gotErr = null;
  try {
    source.emit('error', err);
  } catch (e) {
    gotErr = e;
  }

  assert.strictEqual(gotErr, err);
})();
示例#7
0
test('loop', function (t) {
    t.plan(3 * 2 + 1);
    
    var rs = new Stream;
    rs.readable = true;
    
    var ws = binary()
        .loop(function (end, vars) {
            t.strictEqual(vars, this.vars);
            this
                .word16lu('a')
                .word8u('b')
                .word8s('c')
                .tap(function (vars_) {
                    t.strictEqual(vars, vars_);
                    if (vars.c < 0) end();
                })
            ;
        })
        .tap(function (vars) {
            t.same(vars, { a : 1337, b : 55, c : -5 });
        })
    ;
    rs.pipe(ws);
    
    setTimeout(function () {
        rs.emit('data', new Buffer([ 2, 10, 88 ]));
    }, 10);
    setTimeout(function () {
        rs.emit('data', new Buffer([ 100, 3, 6, 242, 30 ]));
    }, 20);
    setTimeout(function () {
        rs.emit('data', new Buffer([ 60, 60, 199, 44 ]));
    }, 30);
    
    setTimeout(function () {
        rs.emit('data', new Buffer([ 57, 5 ]));
    }, 80);
    setTimeout(function () {
        rs.emit('data', new Buffer([ 55, 251 ]));
    }, 90);
    setTimeout(function () {
        rs.emit('end');
    }, 100);
});
示例#8
0
tape('piping to a request object', function(t) {
  s.once('/push', server.createPostValidator('mydata'))

  var mydata = new stream.Stream()
  mydata.readable = true

  var r1 = request.put({
    url: s.url + '/push'
  }, function(err, res, body) {
    t.equal(err, null)
    t.equal(res.statusCode, 200)
    t.equal(body, 'mydata')
    t.end()
  })
  mydata.pipe(r1)

  mydata.emit('data', 'mydata')
  mydata.emit('end')
})
示例#9
0
tape('piping to a request object with a json body', function(t) {
  s.once('/push-json', server.createPostValidator('{"foo":"bar"}', 'application/json'))

  var mybodydata = new stream.Stream()
  mybodydata.readable = true

  var r2 = request.put({
    url: s.url + '/push-json',
    json: true
  }, function(err, res, body) {
    t.equal(err, null)
    t.equal(res.statusCode, 200)
    t.equal(body, 'OK')
    t.end()
  })
  mybodydata.pipe(r2)

  mybodydata.emit('data', JSON.stringify({ foo: 'bar' }))
  mybodydata.emit('end')
})
示例#10
0
function chooseIn(list, propertyName, callback) {
    var next = function() {
        process.stdout.write('enter your choice: ');
        utils.readInput(function(v) {
            var index = parseInt(v, 10);
            if (list.length > index) callback(index, list[index]);
            else chooseIn(list, propertyName, callback);
        });
    }
    var stream = new Stream();
    pump(stream, process.stdout);
    if (usePager(list.length)) {
        var pager = utils.pipe(process.env.PAGER || "less", []);
        stream.pipe(pager.stdin);
        pager.on('exit', next);
    } else {
        stream.on('close', next);
    }
    formatListIn(stream, list, propertyName);
    stream.emit('close');
}
示例#11
0
        it('should create a new KLV stream with custom key kength and transform the incoming stream into a KLV', function(done) {
            
            var testKLV = new Buffer([
                // Key length of 18
                0x03, 0x2E, 0x5F, 0xAB, 0x08, 0x12, 0x2F, 0x0C, 0xEE, 0x33, 0x00, 0x01, 0x02, 0x45, 0x6D, 0xDD, 0x55, 0x67,
                0x83, 0x00, 0x00, 0x05,
                0x05, 0x04, 0x03, 0x02, 0x01])

            var valueEventReceived = false;

            // Create a simple read stream for the testKLV bytes
            var byteStream = new stream.Stream();
            byteStream.readable = true;

            var klvStream = klv.createStream({keyLength: 18});
            byteStream.pipe(klvStream);

            klvStream.on('key', function(key) {
                assert(key);
                assert.equal(key.length, 18);
                assert.deepEqual(key, testKLV.slice(0, 18));
            });

            klvStream.on('value', function(value) {
                assert(value);
                assert.equal(typeof value, 'object');
                assert.equal(value.length, 5);
                assert.deepEqual(value, testKLV.slice(22));
                valueEventReceived = true;
            });

            klvStream.on('end', function() {
                assert(valueEventReceived);
                done();
            });

            // Emit the KLV 
            byteStream.emit('data', testKLV);
            byteStream.emit('end');
        });
示例#12
0
 s.listen(s.port, function() {
   counter = 0;
   var check = function() {
     counter = counter - 1;
     if (counter === 0) {
       console.log('All tests passed.');
       setTimeout(function() {
         process.exit();
       }, 500);
     }
   };
   s.once('/push', server.createPostValidator("mydata"));
   var mydata = new stream.Stream();
   mydata.readable = true;
   counter++;
   var r1 = request.put({url: 'http://localhost:3453/push'}, function() {
     check();
   });
   mydata.pipe(r1);
   mydata.emit('data', 'mydata');
   mydata.emit('end');
   s.once('/pull', server.createGetResponse("mypulldata"));
   var mypulldata = new stream.Stream();
   mypulldata.writable = true;
   counter++;
   request({url: 'http://localhost:3453/pull'}).pipe(mypulldata);
   var d = '';
   mypulldata.write = function(chunk) {
     d += chunk;
   };
   mypulldata.end = function() {
     assert.equal(d, 'mypulldata');
     check();
   };
   s.on('/cat', function(req, resp) {
     if (req.method === "GET") {
       resp.writeHead(200, {
         'content-type': 'text/plain-test',
         'content-length': 4
       });
       resp.end('asdf');
     } else if (req.method === "PUT") {
       assert.equal(req.headers['content-type'], 'text/plain-test');
       assert.equal(req.headers['content-length'], 4);
       var validate = '';
       req.on('data', function(chunk) {
         validate += chunk;
       });
       req.on('end', function() {
         resp.writeHead(201);
         resp.end();
         assert.equal(validate, 'asdf');
         check();
       });
     }
   });
   s.on('/pushjs', function(req, resp) {
     if (req.method === "PUT") {
       assert.equal(req.headers['content-type'], 'text/javascript');
       check();
     }
   });
   s.on('/catresp', function(req, resp) {
     request.get('http://localhost:3453/cat').pipe(resp);
   });
   s.on('/doodle', function(req, resp) {
     if (req.headers['x-oneline-proxy']) {
       resp.setHeader('x-oneline-proxy', 'yup');
     }
     resp.writeHead('200', {'content-type': 'image/png'});
     fs.createReadStream(path.join(__dirname, 'googledoodle.png')).pipe(resp);
   });
   s.on('/onelineproxy', function(req, resp) {
     var x = request('http://localhost:3453/doodle');
     req.pipe(x);
     x.pipe(resp);
   });
   counter++;
   fs.createReadStream(__filename).pipe(request.put('http://localhost:3453/pushjs'));
   counter++;
   request.get('http://localhost:3453/cat').pipe(request.put('http://localhost:3453/cat'));
   counter++;
   request.get('http://localhost:3453/catresp', function(e, resp, body) {
     assert.equal(resp.headers['content-type'], 'text/plain-test');
     assert.equal(resp.headers['content-length'], 4);
     check();
   });
   var doodleWrite = fs.createWriteStream(path.join(__dirname, 'test.png'));
   counter++;
   request.get('http://localhost:3453/doodle').pipe(doodleWrite);
   doodleWrite.on('close', function() {
     assert.deepEqual(fs.readFileSync(path.join(__dirname, 'googledoodle.png')), fs.readFileSync(path.join(__dirname, 'test.png')));
     check();
   });
   process.on('exit', function() {
     fs.unlinkSync(path.join(__dirname, 'test.png'));
   });
   counter++;
   request.get({
     uri: 'http://localhost:3453/onelineproxy',
     headers: {'x-oneline-proxy': 'nope'}
   }, function(err, resp, body) {
     assert.equal(resp.headers['x-oneline-proxy'], 'yup');
     check();
   });
   s.on('/afterresponse', function(req, resp) {
     resp.write('d');
     resp.end();
   });
   counter++;
   var afterresp = request.post('http://localhost:3453/afterresponse').on('response', function() {
     var v = new ValidationStream('d');
     afterresp.pipe(v);
     v.on('end', check);
   });
   s.on('/forward1', function(req, resp) {
     resp.writeHead(302, {location: '/forward2'});
     resp.end();
   });
   s.on('/forward2', function(req, resp) {
     resp.writeHead('200', {'content-type': 'image/png'});
     resp.write('d');
     resp.end();
   });
   counter++;
   var validateForward = new ValidationStream('d');
   validateForward.on('end', check);
   request.get('http://localhost:3453/forward1').pipe(validateForward);
   s.once('/opts', server.createGetResponse('opts response'));
   var optsStream = new stream.Stream();
   optsStream.writable = true;
   var optsData = '';
   optsStream.write = function(buf) {
     optsData += buf;
     if (optsData === 'opts response') {
       setTimeout(check, 10);
     }
   };
   optsStream.end = function() {
     assert.fail('end called');
   };
   counter++;
   request({url: 'http://localhost:3453/opts'}).pipe(optsStream, {end: false});
 });
示例#13
0
s.listen(s.port, function () {
    counter = 0;

    var check = function () {
        counter = counter - 1
        if (counter === 0) {
            console.log('All tests passed.')
            setTimeout(function () {
                process.exit();
            }, 500)
        }
    }

    // Test pipeing to a request object
    s.once('/push', server.createPostValidator("mydata"));

    var mydata = new stream.Stream();
    mydata.readable = true

    counter++
    var r1 = request.put({url: 'http://localhost:3453/push'}, function () {
        check();
    })
    mydata.pipe(r1)

    mydata.emit('data', 'mydata');
    mydata.emit('end');

    // Test pipeing to a request object with a json body
    s.once('/push-json', server.createPostValidator("{\"foo\":\"bar\"}", "application/json"));

    var mybodydata = new stream.Stream();
    mybodydata.readable = true

    counter++
    var r2 = request.put({url: 'http://localhost:3453/push-json', json: true}, function () {
        check();
    })
    mybodydata.pipe(r2)

    mybodydata.emit('data', JSON.stringify({foo: "bar"}));
    mybodydata.emit('end');

    // Test pipeing from a request object.
    s.once('/pull', server.createGetResponse("mypulldata"));

    var mypulldata = new stream.Stream();
    mypulldata.writable = true

    counter++
    request({url: 'http://localhost:3453/pull'}).pipe(mypulldata)

    var d = '';

    mypulldata.write = function (chunk) {
        d += chunk;
    }
    mypulldata.end = function () {
        assert.equal(d, 'mypulldata');
        check();
    };


    s.on('/cat', function (req, resp) {
        if (req.method === "GET") {
            resp.writeHead(200, {'content-type': 'text/plain-test', 'content-length': 4});
            resp.end('asdf')
        } else if (req.method === "PUT") {
            assert.equal(req.headers['content-type'], 'text/plain-test');
            assert.equal(req.headers['content-length'], 4)
            var validate = '';

            req.on('data', function (chunk) {
                validate += chunk
            })
            req.on('end', function () {
                resp.writeHead(201);
                resp.end();
                assert.equal(validate, 'asdf');
                check();
            })
        }
    })
    s.on('/pushjs', function (req, resp) {
        if (req.method === "PUT") {
            assert.equal(req.headers['content-type'], 'application/javascript');
            check();
        }
    })
    s.on('/catresp', function (req, resp) {
        request.get('http://localhost:3453/cat').pipe(resp)
    })
    s.on('/doodle', function (req, resp) {
        if (req.headers['x-oneline-proxy']) {
            resp.setHeader('x-oneline-proxy', 'yup')
        }
        resp.writeHead('200', {'content-type': 'image/jpeg'})
        fs.createReadStream(path.join(__dirname, 'googledoodle.jpg')).pipe(resp)
    })
    s.on('/onelineproxy', function (req, resp) {
        var x = request('http://localhost:3453/doodle')
        req.pipe(x)
        x.pipe(resp)
    })

    counter++
    fs.createReadStream(__filename).pipe(request.put('http://localhost:3453/pushjs'))

    counter++
    request.get('http://localhost:3453/cat').pipe(request.put('http://localhost:3453/cat'))

    counter++
    request.get('http://localhost:3453/catresp', function (e, resp, body) {
        assert.equal(resp.headers['content-type'], 'text/plain-test');
        assert.equal(resp.headers['content-length'], 4)
        check();
    })

    var doodleWrite = fs.createWriteStream(path.join(__dirname, 'test.jpg'))

    counter++
    request.get('http://localhost:3453/doodle').pipe(doodleWrite)

    doodleWrite.on('close', function () {
        assert.deepEqual(fs.readFileSync(path.join(__dirname, 'googledoodle.jpg')), fs.readFileSync(path.join(__dirname, 'test.jpg')))
        check()
    })

    process.on('exit', function () {
        fs.unlinkSync(path.join(__dirname, 'test.jpg'))
    })

    counter++
    request.get({uri: 'http://localhost:3453/onelineproxy', headers: {'x-oneline-proxy': 'nope'}}, function (err, resp, body) {
        assert.equal(resp.headers['x-oneline-proxy'], 'yup')
        check()
    })

    s.on('/afterresponse', function (req, resp) {
        resp.write('d')
        resp.end()
    })

    counter++
    var afterresp = request.post('http://localhost:3453/afterresponse').on('response', function () {
        var v = new ValidationStream('d')
        afterresp.pipe(v)
        v.on('end', check)
    })

    s.on('/forward1', function (req, resp) {
        resp.writeHead(302, {location: '/forward2'})
        resp.end()
    })
    s.on('/forward2', function (req, resp) {
        resp.writeHead('200', {'content-type': 'image/png'})
        resp.write('d')
        resp.end()
    })

    counter++
    var validateForward = new ValidationStream('d')
    validateForward.on('end', check)
    request.get('http://localhost:3453/forward1').pipe(validateForward)

    // Test pipe options
    s.once('/opts', server.createGetResponse('opts response'));

    var optsStream = new stream.Stream();
    optsStream.writable = true

    var optsData = '';
    optsStream.write = function (buf) {
        optsData += buf;
        if (optsData === 'opts response') {
            setTimeout(check, 10);
        }
    }

    optsStream.end = function () {
        assert.fail('end called')
    };

    counter++
    request({url: 'http://localhost:3453/opts'}).pipe(optsStream, { end: false })
})
示例#14
0
s.listen(s.port, function () {
    counter = 0;

    var check = function () {
        counter = counter - 1
        if (counter === 0) {
            console.log('All tests passed.')
            setTimeout(function () {
                process.exit();
            }, 500)
        }
    }

    // Test pipeing to a request object
    s.once('/push', server.createPostValidator("mydata"));

    var mydata = new stream.Stream();
    mydata.readable = true

    counter++
    var r1 = request.put({url:'http://localhost:3453/push'}, function () {
        check();
    })
    mydata.pipe(r1)

    mydata.emit('data', 'mydata');
    mydata.emit('end');


    // Test pipeing from a request object.
    s.once('/pull', server.createGetResponse("mypulldata"));

    var mypulldata = new stream.Stream();
    mypulldata.writable = true

    counter++
    request({url:'http://localhost:3453/pull'}).pipe(mypulldata)

    var d = '';

    mypulldata.write = function (chunk) {
        d += chunk;
    }
    mypulldata.end = function () {
        assert.equal(d, 'mypulldata');
        check();
    };


    s.on('/cat', function (req, resp) {
        if (req.method === "GET") {
            resp.writeHead(200, {'content-type':'text/plain-test', 'content-length':4});
            resp.end('asdf')
        } else if (req.method === "PUT") {
            assert.equal(req.headers['content-type'], 'text/plain-test');
            assert.equal(req.headers['content-length'], 4)
            var validate = '';

            req.on('data', function (chunk) {
                validate += chunk
            })
            req.on('end', function () {
                resp.writeHead(201);
                resp.end();
                assert.equal(validate, 'asdf');
                check();
            })
        }
    })
    s.on('/pushjs', function (req, resp) {
        if (req.method === "PUT") {
            assert.equal(req.headers['content-type'], 'text/javascript');
            check();
        }
    })
    s.on('/catresp', function (req, resp) {
        request.get('http://localhost:3453/cat').pipe(resp)
    })
    s.on('/doodle', function (req, resp) {
        if (req.headers['x-oneline-proxy']) {
            resp.setHeader('x-oneline-proxy', 'yup')
        }
        resp.writeHead('200', {'content-type':'image/png'})
        fs.createReadStream(path.join(__dirname, 'googledoodle.png')).pipe(resp)
    })
    s.on('/onelineproxy', function (req, resp) {
        var x = request('http://localhost:3453/doodle')
        req.pipe(x)
        x.pipe(resp)
    })

    counter++
    fs.createReadStream(__filename).pipe(request.put('http://localhost:3453/pushjs'))

    counter++
    request.get('http://localhost:3453/cat').pipe(request.put('http://localhost:3453/cat'))

    counter++
    request.get('http://localhost:3453/catresp', function (e, resp, body) {
        assert.equal(resp.headers['content-type'], 'text/plain-test');
        assert.equal(resp.headers['content-length'], 4)
        check();
    })

    var doodleWrite = fs.createWriteStream(path.join(__dirname, 'test.png'))

    counter++
    request.get('http://localhost:3453/doodle').pipe(doodleWrite)

    doodleWrite.on('close', function () {
        assert.deepEqual(fs.readFileSync(path.join(__dirname, 'googledoodle.png')), fs.readFileSync(path.join(__dirname, 'test.png')))
        check()
    })

    process.on('exit', function () {
        fs.unlinkSync(path.join(__dirname, 'test.png'))
    })

    counter++
    request.get({uri:'http://localhost:3453/onelineproxy', headers:{'x-oneline-proxy':'nope'}}, function (err, resp, body) {
        assert.equal(resp.headers['x-oneline-proxy'], 'yup')
        check()
    })

    s.on('/afterresponse', function (req, resp) {
        resp.write('d')
        resp.end()
    })

    counter++
    var afterresp = request.post('http://localhost:3453/afterresponse').on('response', function () {
        var v = new ValidationStream('d')
        afterresp.pipe(v)
        v.on('end', check)
    })

})
'use strict';
const common = require('../common');
const assert = require('assert');
const Stream = require('stream').Stream;

{
  const source = new Stream();
  const dest = new Stream();

  source.pipe(dest);

  let gotErr = null;
  source.on('error', function(err) {
    gotErr = err;
  });

  const err = new Error('This stream turned into bacon.');
  source.emit('error', err);
  assert.strictEqual(gotErr, err);
}

{
  const source = new Stream();
  const dest = new Stream();

  source.pipe(dest);

  const err = new Error('This stream turned into bacon.');

  let gotErr = null;
  try {
示例#16
0
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
// This test ensures SourceStream.pipe(DestStream) returns DestStream

require('../common');
const Stream = require('stream').Stream;
const assert = require('assert');

const sourceStream = new Stream();
const destStream = new Stream();
const result = sourceStream.pipe(destStream);

assert.strictEqual(result, destStream);
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

/*<replacement>*/
var bufferShim = require('safe-buffer').Buffer;
/*</replacement>*/
var common = require('../common');
var assert = require('assert/');
var Stream = require('stream').Stream;

{
  var source = new Stream();
  var dest = new Stream();

  source.pipe(dest);

  var gotErr = null;
  source.on('error', function (err) {
    gotErr = err;
  });

  var err = new Error('This stream turned into bacon.');
  source.emit('error', err);
  assert.strictEqual(gotErr, err);
}

{
  var _source = new Stream();
  var _dest = new Stream();
示例#18
0
    console.log('All tests passed.')
    process.exit();
  }
}

// Test pipeing to a request object
s.once('/push', server.createPostValidator("mydata"));

var mydata = new stream.Stream();
mydata.readable = true

var r1 = request.put({url:'http://localhost:3453/push'}, function () {
  passes += 1;
  check();
})
mydata.pipe(r1)

mydata.emit('data', 'mydata');
mydata.emit('end');


// Test pipeing from a request object.
s.once('/pull', server.createGetResponse("mypulldata"));

var mypulldata = new stream.Stream();
mypulldata.writable = true

request({url:'http://localhost:3453/pull'}).pipe(mypulldata)

var d = '';
'use strict';
const common = require('../common');
const stream = require('stream');

const r = new stream.Stream();
r.listenerCount = undefined;

const w = new stream.Stream();
w.listenerCount = undefined;

w.on('pipe', function() {
  r.emit('error', new Error('Readable Error'));
  w.emit('error', new Error('Writable Error'));
});
r.on('error', common.mustCall(noop));
w.on('error', common.mustCall(noop));
r.pipe(w);

function noop() {}