示例#1
0
  'test pause()': function(defer){
    var calls = 0
      , data = []
      , req = new Stream;

    req.write = function(data){
      this.emit('data', data);
    };
    req.end = function(){
      this.emit('end');
    };

    var pause = utils.pause(req);

    req.write('one');
    req.write('two');
    req.end();

    req.on('data', function(chunk){
      ++calls;
      data.push(chunk);
    });
    req.on('end', function(){
      ++calls;
      data.should.have.length(2);
    });

    pause.resume();

    defer(function(){
      calls.should.equal(3);
    });
  },
示例#2
0
                function (e, css) {
                    if(e)
                        console.log(file.path+'\nline:'+e.line+': '+e.extract[2]+'\n'+e.message)

                    var f = file.path.split('.')
                    f[f.length-1] = 'css'

                    file.path = f.join('.')
                    file.contents = new Buffer(css||'')
                    stream.emit('data',file)

                    pending--
                    stream.end()
                }
示例#3
0
test('cycles', function (t) {
  outstr.on('end', function () {
    output.forEach(function (o, i) {
      // Drop variable parts for comparison.
      delete o.hostname;
      delete o.pid;
      delete o.time;
      // Hack object/dict comparison: JSONify.
      t.equal(JSON.stringify(o), JSON.stringify(expect[i]),
        'log item ' + i + ' matches');
    });
    t.end();
  });

  var obj = { bang: 'boom' };
  obj.KABOOM = obj;
  log.info('bango', obj);
  log.info('kaboom', obj.KABOOM);
  log.info(obj);
  outstr.end();
  t.ok('did not throw');
});
示例#4
0
 function next (err) {
   inNext = true
   outputs ++
   var args = [].slice.call(arguments)
   if(err) {
     args.unshift('error')
     return inNext = false, stream.emit.apply(stream, args)
   }
   args.shift() //drop err
 
   if (args.length){
     args.unshift('data')
     r = stream.emit.apply(stream, args)
   }
   if(inputs == outputs) {
     if(paused) stream.emit('drain') //written all the incoming events
     paused = false
     if(ended)
       stream.end()
   }
   inNext = false
 }
示例#5
0
文件: garner.js 项目: joelcox/garner
    it('..umh, does some processing!', function(done) {

      // Mock out a stream
      var csvStream = new stream.Stream();
      csvStream.writable = true;

      csvStream.write = function (data) {
        this.emit('record', data);
        return true;
      }

      csvStream.end = function (data) {
        this.emit('end')
      }

      garn.groupBy('hair-color');
      garn.groupByRelative('hair-color');
      garn.first('weight');

      garn.process(csvStream, function(err, results) {
        results.hairColor.operations.groupBy.blonde.should.eql(1);
        results.hairColor.operations.groupBy.black.should.eql(2);
        results.hairColor.operations.groupByRelative.blonde.should.eql(0.3333333333333333);
        results.hairColor.operations.groupByRelative.black.should.eql(0.6666666666666666);
        results.weight.operations.first.should.eql(71);
        results._rows.should.eql(3);
        done();
      });

      csvStream.write(['eye-color', 'hair-color', 'weight']);
      csvStream.write(['blue', 'blonde', 71]);
      csvStream.write(['blue', 'black', 82]);
      csvStream.write(['brown', 'black', 87]);
      csvStream.end();

    });
示例#6
0
文件: sax.js 项目: mikeal/sax-js
 parser.onend = function () {
   stream.end()
   if (val) val()
 }
示例#7
0
文件: sax.js 项目: mikeal/sax-js
 parser.onend = function () {
   stream.end()
 };
示例#8
0
 }, function(obj) {
   s.end(obj);
 });