src/VarStream.js
function VarStream(rootObject, rootProperty, options) {
  var self = this;

  // Ensure new were used
  if(!(this instanceof VarStream)) {
    return new VarStream(rootObject, rootProperty, options);
  }

  // Ensure we had root object and property
  if(!(rootObject instanceof Object)) {
    throw new Error('No root object provided.');
  }
  if('string' !== typeof rootProperty || rootProperty == '') {
    throw new Error('No root property name given.');
  }

  // Parent constructor
  DuplexStream.call(this);

  this._varstreamReader=new VarStreamReader(rootObject, rootProperty,
    options ? options&VarStreamReader.OPTIONS : 0);

  this._varstreamWriter = new VarStreamWriter(function(str) {
      self.push(new Buffer(str, 'utf8'));
  }, options ? options&VarStreamWriter.OPTIONS : 0);

  // Parse input
  this._write = function _write(chunk, encoding, done) {
    this._varstreamReader.read(chunk.toString(
      encoding !== 'buffer' ? encoding : 'utf8'
    ));
    done();
  };

  // Output data
  this._read = function _read() {
    this._varstreamWriter.write(rootObject[rootProperty]);
    this.push(null);
  };

}
function VarStream(rootObject, rootProperty, options) {
  var self = this;

  // Ensure new were used
  if(!(this instanceof VarStream)) {
    return new VarStream(rootObject, rootProperty, options);
  }

  // Ensure we had root object and property
  if(!(rootObject instanceof Object)) {
    throw new Error('No root object provided.');
  }
  if('string' !== typeof rootProperty || rootProperty == '') {
    throw new Error('No root property name given.');
  }

  // Parent constructor
  DuplexStream.call(this);

  this._varstreamReader=new VarStreamReader(rootObject, rootProperty,
    options ? options&VarStreamReader.OPTIONS : 0);

  this._varstreamWriter = new VarStreamWriter(function(str) {
      self.push(new Buffer(str, 'utf8'));
  }, options ? options&VarStreamWriter.OPTIONS : 0);

  // Parse input
  this._write = function _write(chunk, encoding, done) {
    this._varstreamReader.read(chunk.toString(
      encoding !== 'buffer' ? encoding : 'utf8'
    ));
    done();
  };

  // Output data
  this._read = function _read() {
    this._varstreamWriter.write(rootObject[rootProperty]);
    this.push(null);
  };

}
function VarStream ( rootObject , rootProperty , options ) { var self = this ; // Ensure new were used
 if ( ! ( this instanceof VarStream ) ) { return new VarStream ( rootObject , rootProperty , options ) ; } // Ensure we had root object and property
 if ( ! ( rootObject instanceof Object ) ) { throw new Error ( 'No root object provided.' ) ; } if ( 'string' !== typeof rootProperty || ootProperty  =  ') throw new Error ( 'No root property name given.' ) ; } // Parent constructor
 DuplexStream . call ( this ) ; this . _varstreamReader = new VarStreamReader ( rootObject , rootProperty , options ? options & VarStreamReader . OPTIONS : 0 ) ; this . _varstreamWriter = new VarStreamWriter ( function ( str ) { self . push ( new Buffer ( str , 'utf8' ) ) ; } , options ? options & VarStreamWriter . OPTIONS : 0 ) ; // Parse input
 this . _write = function _write ( chunk , encoding , done ) { this . _varstreamReader . read ( chunk . toString ( encoding !== 'buffer' ? encoding : 'utf8' ) ) ; done ( ) ; } ; // Output data
 this . _read = function _read ( ) { this . _varstreamWriter . write ( rootObject [ rootProperty ] ) ; this . push ( null ) ; } ; }
Constructor
Constructor