ext/stream.class.js
function ChannelStream(chan, encoding){
  if(!encoding) encoding = 'binary';
  if(typeof chan != 'object' || !chan.isChannel)
  {
    log.warn('invalid channel passed to streamize');
    return false;
  }

  var allowHalfOpen = (chan.type === "thtp") ? true : false;

  Duplex.call(this,{allowHalfOpen: allowHalfOpen, objectMode:true})
  this.on('finish',function(){
    chan.send({json:{end:true}});
  });

  this.on('error',function(err){
    if(err == chan.err) return; // ignore our own generated errors
    chan.send({json:{err:err.toString()}});
  });
  var stream = this

  this.on('pipe', function(from){
    from.on('end',function(){
      stream.end()
    })
  })


  chan.receiving = chan_to_stream(this);

  this._chan = chan;
  this._encoding = encoding;

  return this;
}
function ChannelStream(chan, encoding){
  if(!encoding) encoding = 'binary';
  if(typeof chan != 'object' || !chan.isChannel)
  {
    log.warn('invalid channel passed to streamize');
    return false;
  }

  var allowHalfOpen = (chan.type === "thtp") ? true : false;

  Duplex.call(this,{allowHalfOpen: allowHalfOpen, objectMode:true})
  this.on('finish',function(){
    chan.send({json:{end:true}});
  });

  this.on('error',function(err){
    if(err == chan.err) return; // ignore our own generated errors
    chan.send({json:{err:err.toString()}});
  });
  var stream = this

  this.on('pipe', function(from){
    from.on('end',function(){
      stream.end()
    })
  })


  chan.receiving = chan_to_stream(this);

  this._chan = chan;
  this._encoding = encoding;

  return this;
}
function ChannelStream ( chan , encoding ) { if ( ! encoding ) encoding = 'binary' ; if ( typeof chan != 'object' || ! chan . isChannel ) { log . warn ( 'invalid channel passed to streamize' ) ; return false ; } var allowHalfOpen = ( chan . type === "thtp" ) ? true : false ; Duplex . call ( this , { allowHalfOpen : allowHalfOpen , objectMode : true } ) this . on ( 'finish' , function ( ) { chan . send ( { json : { end : true } } ) ; } ) ; this . on ( 'error' , function ( err ) { if ( err == chan . err ) return ; // ignore our own generated errors chan . send ( { json : { err : err . toString ( ) } } ) ; } ) ; var stream = this this . on ( 'pipe' , function ( from ) { from . on ( 'end' , function ( ) { stream . end ( ) } ) } ) chan . receiving = chan_to_stream ( this ) ; this . _chan = chan ; this . _encoding = encoding ; return this ; }
ChannelStream impliments a Duplex stream API over Telehash channels.
for Duplex stream usage, consult core node docs. for an idea of how you might
expand upon streams within the Telehash ecosystem, see thtp
@class ChannelStream
@constructor
@param {Channel} channel - a Telehash channel (generated by e3x)
@param {stringa} encoding - 'binary' or 'json'
@return {Stream}
ChannelStream impliments a Duplex stream API over Telehash channels . for Duplex stream usage consult core node docs . for an idea of how you might expand upon streams within the Telehash ecosystem see thtp