示例#1
0
文件: sax.js 项目: HenryRawas/sax-js
function SAXStream (strict, opt) {
  Stream.apply(me)

  this._parser = new SAXParser(strict, opt)
  this.writable = true
  this.readable = true


  var me = this

  this._parser.onend = function () {
    me.emit("end")
  }

  this._parser.onerror = function (er) {
    me.emit("error", er)
  }

  streamWraps.forEach(function (ev) {
    Object.defineProperty(me, "on" + ev, {
      get: function () { return me._parser["on" + ev] },
      set: function (h) {
        if (!h) {
          me.removeAllListeners(ev)
          return me._parser["on"+ev] = h
        }
        me.on(ev, h)
      },
      enumerable: true,
      configurable: false
    })
  })
}
示例#2
0
 function EntryWriter(props) {
   var me = this;
   if (!(me instanceof EntryWriter)) {
     return new EntryWriter(props);
   }
   Stream.apply(this);
   me.writable = true;
   me.readable = true;
   me._stream = new BlockStream(512);
   me._stream.on("data", function(c) {
     me.emit("data", c);
   });
   me._stream.on("drain", function() {
     me.emit("drain");
   });
   me._stream.on("end", function() {
     me.emit("end");
     me.emit("close");
   });
   me.props = props;
   if (props.type === "Directory") {
     props.size = 0;
   }
   props.ustar = "ustar\0";
   props.ustarver = "00";
   me.path = props.path;
   me._buffer = [];
   me._didHeader = false;
   me._meta = false;
   me.on("pipe", function() {
     me._process();
   });
 }
示例#3
0
function Extract (opts) {
  var self = this;
  if (!(this instanceof Extract)) {
    return new Extract(opts);
  }

  Stream.apply(this);

  this.writable = true;
  this.readable = true;

  this._parser = Parse();
  this._parser.on('error', function(err) {
    self.emit('error', err);
  });

  var writer = Writer(opts);
  writer.on('error', function(err) {
    self.emit('error', err);
  });
  writer.on('close', function() {
    self.emit("end");
    self.emit("close");
  });

  this._parser.pipe(writer);
}
示例#4
0
文件: streams.js 项目: jpalardy/ssej
var BaseStream = this.BaseStream = function () {
    Stream.apply(this, arguments);

    this.readable = true;
    this.writable = true;

    this._open = false;
};
function StringifyStream (object) {
    Stream.apply(this);
    this.on('newListener', function(event, listener) {
        if(event === 'data') {
            this._start();
        }
    });
}
示例#6
0
var CopyToStream = function () {
  Stream.apply(this, arguments);
  this._error = false;
  this._finished = false;
  this._paused = false;
  this.buffer = new Buffer(0);
  this._encoding = undefined;
  this.__defineGetter__('readable', this._readable.bind(this));
};
示例#7
0
var CopyFromStream = function () {
  Stream.apply(this, arguments);
  this._buffer = new Buffer(0);
  this._connection = false;
  this._finished  = false;
  this._finishedSent = false;
  this._closed = false;
  this._error = false;
  this._dataBuffered = false;
  this.__defineGetter__("writable", this._writable.bind(this));
};
示例#8
0
function PullStream() {
  var self = this;
  Stream.apply(this);
  this.readable = false;
  this.writable = true;
  this._buffer = new streamBuffers.WritableStreamBuffer();
  this.paused = false;
  this._positionInStream = 0;
  this._recvEnd = false;
  this._serviceRequests = null;
  this.eof = false;
  this._srcStream = null;
  this.on('pipe', function (srcStream) {
    self._srcStream = srcStream;
  });
}
/* ========================================================================== *
 *  CONSTRUCTOR & INITIALIZATION                                              *
 * ========================================================================== */
function Spout(dataPackets) {
  var self = this;
  
  if (!Array.isArray(dataPackets))
    dataPackets = [dataPackets];

  this.dataPackets = dataPackets;

  this.writable = true;
  Stream.apply(this);

  process.nextTick(function () {
    for (var i = 0, ii = self.dataPackets.length; i < ii; i++)
      self.emit('data', self.dataPackets[i]);
    
    self.emit('end');
  });
};
示例#10
0
文件: sax.js 项目: tracyapps/chad
	function SAXStream( strict, opt ) {
		if( !(this instanceof SAXStream) ) return new SAXStream( strict, opt )

		Stream.apply( this )

		this._parser = new SAXParser( strict, opt )
		this.writable = true
		this.readable = true


		var me = this

		this._parser.onend = function() {
			me.emit( "end" )
		}

		this._parser.onerror = function( er ) {
			me.emit( "error", er )

			// if didn't throw, then means error was handled.
			// go ahead and clear error, so we can write again.
			me._parser.error = null
		}

		this._decoder = null;

		streamWraps.forEach( function( ev ) {
			Object.defineProperty( me, "on" + ev, {
				get: function() {
					return me._parser["on" + ev]
				},
				set: function( h ) {
					if( !h ) {
						me.removeAllListeners( ev )
						return me._parser["on" + ev] = h
					}
					me.on( ev, h )
				},
				enumerable: true,
				configurable: false
			} )
		} )
	}
示例#11
0
文件: websocket.js 项目: 0x00A/tsd
function Socket(socket) {
  Stream.apply(this, arguments);

  this.socket = socket;
  this.readable = true;
  this.writable = true;

  var that = this;

  var on = function(name, fn) {
    if (socket.on) {
      socket.on(name, fn);
    } else {
      socket['on' + name] = fn;
    }
  };

  on('message', function(message) {
    if (message && message.srcElement && message instanceof MessageEvent) {
      message = message.data;
    }

    that.emit('data', message);
  });

  on('close', function() {
    that.emit('end');
  });

  on('error', function(err) {
    that.emit('error', err);
  });

  var handleConnection = function() {
    that.emit('connection');
  };

  on('open', handleConnection);
  on('connection', handleConnection);
}
示例#12
0
文件: tar.js 项目: 3vr/tar-async
	function Tar(opt) {
		var tape = this;

		opt = opt || {};

		blockSize = (opt.recordsPerBlock ? opt.recordsPerBlock : 20) * recordSize;

		Stream.apply(this, arguments);

		this.written = 0;

		this.consolidate = 'consolidate' in opt ? opt.consolidate : false;
		this.normalize = 'normalize' in opt ? opt.normalize : true;

		this.on('end', function () {
			tape.emit('data', utils.clean(blockSize - (tape.written % blockSize)));
			tape.written += blockSize - (tape.written % blockSize);
		});

		if (opt && opt.output) {
			this.pipe(opt.output);
		}
	}
示例#13
0
文件: serverV2.js 项目: AoJ/LoggerV2
function BufferStream () {
    Stream.apply(this);
    this.finished = false;
    this.writable = true;
}
示例#14
0
function FakeStream() {
  Stream.apply(this);
  this.wait = false;
  this.writable = true;
  this.readable = true;
}
示例#15
0
文件: abridge.js 项目: Chuwiey/Orbit
function Minifier() {
  Stream.apply(this);
  this.readable = true;
};