index.js
function addData(data) {
    if (options.objectMode) {
      if (!this.data) {
        this.data = [data];
      } else {
        this.data.push(data);
      }
      this.totalDataLen += 1;
    } else if (typeof data !== 'string' && !(data instanceof Buffer)) {
      throw new TypeError(`expected string or Buffer, got ${
        Object.prototype.toString.call(data)}.  Need objectMode?`);
    } else if (this.data === null || this.data === undefined) {
      this.data = data;
      this.totalDataLen += data.length;
    } else if (typeof this.data === 'string' && typeof data === 'string') {
      // perf:  Avoid unnecessary string concatenation
      if (this.data.length === 0) {
        this.data = data;
      } else if (data.length > 0) {
        this.data += data;
      }
      this.totalDataLen += data.length;
    } else if (this.data instanceof Buffer && data instanceof Buffer) {
      // perf:  Avoid unnecessary Buffer concatenation
      if (this.data.length === 0) {
        this.data = data;
      } else if (data.length > 0) {
        // FIXME:  Potential performance issue if data or this.data are large.
        // Should append to a Buffer we control and store a slice in .data
        this.data = Buffer.concat(
          [this.data, data],
          this.data.length + data.length
        );
      }
      this.totalDataLen += data.length;
    } else {
      throw new TypeError(`read returned ${
        Object.prototype.toString.call(data)}, previously ${
        Object.prototype.toString.call(this.data)
      }.  Need objectMode?`);
    }
  }
function addData(data) {
    if (options.objectMode) {
      if (!this.data) {
        this.data = [data];
      } else {
        this.data.push(data);
      }
      this.totalDataLen += 1;
    } else if (typeof data !== 'string' && !(data instanceof Buffer)) {
      throw new TypeError(`expected string or Buffer, got ${
        Object.prototype.toString.call(data)}.  Need objectMode?`);
    } else if (this.data === null || this.data === undefined) {
      this.data = data;
      this.totalDataLen += data.length;
    } else if (typeof this.data === 'string' && typeof data === 'string') {
      // perf:  Avoid unnecessary string concatenation
      if (this.data.length === 0) {
        this.data = data;
      } else if (data.length > 0) {
        this.data += data;
      }
      this.totalDataLen += data.length;
    } else if (this.data instanceof Buffer && data instanceof Buffer) {
      // perf:  Avoid unnecessary Buffer concatenation
      if (this.data.length === 0) {
        this.data = data;
      } else if (data.length > 0) {
        // FIXME:  Potential performance issue if data or this.data are large.
        // Should append to a Buffer we control and store a slice in .data
        this.data = Buffer.concat(
          [this.data, data],
          this.data.length + data.length
        );
      }
      this.totalDataLen += data.length;
    } else {
      throw new TypeError(`read returned ${
        Object.prototype.toString.call(data)}, previously ${
        Object.prototype.toString.call(this.data)
      }.  Need objectMode?`);
    }
  }
function addData ( data ) { if ( options . objectMode ) { if ( ! this . data ) { this . data = [ data ] ; } else { this . data . push ( data ) ; } this . totalDataLen += 1 ; } else if ( typeof data !== 'string' && ! ( data instanceof Buffer ) ) { throw new TypeError ( ` ${ Object . prototype . toString . call ( data ) } ` ) ; } else if ( this . data === null || this . data === undefined ) { this . data = data ; this . totalDataLen += data . length ; } else if ( typeof this . data === 'string' && typeof data === 'string' ) { // perf:  Avoid unnecessary string concatenation if ( this . data . length === 0 ) { this . data = data ; } else if ( data . length > 0 ) { this . data += data ; } this . totalDataLen += data . length ; } else if ( this . data instanceof Buffer && data instanceof Buffer ) { // perf:  Avoid unnecessary Buffer concatenation if ( this . data . length === 0 ) { this . data = data ; } else if ( data . length > 0 ) { // FIXME:  Potential performance issue if data or this.data are large. // Should append to a Buffer we control and store a slice in .data this . data = Buffer . concat ( [ this . data , data ] , this . data . length + data . length ) ; } this . totalDataLen += data . length ; } else { throw new TypeError ( ` ${ Object . prototype . toString . call ( data ) } ${ Object . prototype . toString . call ( this . data ) } ` ) ; } }
Adds data to a stream state.

This function should be a method of StreamState, but that would violate
our guarantees.  We call it as if it were to convey this behavior and to
avoid ESLint no-param-reassign.

@this {!StreamState}
@param {*} data Data read from the stream for this StreamState.
@private
Adds data to a stream state .