constructor(xhr) {
    /**
     * @const
     * @private {?googLog.Logger} the logger.
     */
    this.logger_ = googLog.getLogger('XhrStreamReader');

    /**
     * The xhr object passed by the application.
     * @private {?XhrIo} the XHR object for the stream.
     */
    this.xhr_ = xhr;

    /**
     * To be initialized with the correct content-type.
     *
     * @private {?StreamParser} the parser for the stream.
     */
    this.parser_ = null;

    /**
     * The position of where the next unprocessed data starts in the XHR
     * response text.
     * @private {number}
     */
    this.pos_ = 0;

    /**
     * The status (error detail) of the current stream.
     * @private {!XhrStreamReaderStatus}
     */
    this.status_ = XhrStreamReaderStatus.INIT;

    /** @private {boolean} */
    this.hasStreamingResponseData_ = false;

    /** @private {?TextDecoder} */
    this.textDecoder_ = null;

    /**
     * The handler for any status change event.
     *
     * @private {?function()} The call back to handle the XHR status change.
     */
    this.statusHandler_ = null;

    /**
     * The handler for new response data.
     *
     * @private {?function(!Array<!Object>)} The call back to handle new
     * response data, parsed as an array of atomic messages.
     */
    this.dataHandler_ = null;

    /**
     * An object to keep track of event listeners.
     *
     * @private {!EventHandler<!XhrStreamReader>}
     */
    this.eventHandler_ = new EventHandler(this);

    // register the XHR event handler
    this.eventHandler_.listen(
        this.xhr_, EventType.READY_STATE_CHANGE, this.readyStateChangeHandler_);
  }
@param {!XhrIo} xhr The XhrIo object with its response body to
be handled by NodeReadableStream.