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 }) }) }
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(); }); }
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); }
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(); } }); }
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)); };
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)); };
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'); }); };
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 } ) } ) }
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); }
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); } }
function BufferStream () { Stream.apply(this); this.finished = false; this.writable = true; }
function FakeStream() { Stream.apply(this); this.wait = false; this.writable = true; this.readable = true; }
function Minifier() { Stream.apply(this); this.readable = true; };