/* @flow */

const stream = require('stream')

module.exports = class StreamBuilder {
  /*::
  data: string
  */

  constructor() {
    this.data = ''
  }

  push(data /*: string */) /*: StreamBuilder */ {
    this.data += data
    return this
  }

  build() /*: stream.Readable */ {
    const result = new stream.Readable()

    result.push(this.data)
    result.push(null)

    return result
  }
}

@@ -101,16 +101,30 @@
  string%0A
+  err: ?Error%0A
   */%0A%0A  
@@ -158,16 +158,36 @@
 ta = ''%0A
+    this.err = null%0A
   %7D%0A%0A  p
@@ -282,103 +282,325 @@
 %0A%0A  
-build() /*: stream.Readable */ %7B%0A    const result = new stream.Readable()%0A%0A    result.push(this
+error(err /*: Error */) /* StreamBuilder */ %7B%0A    this.err = err%0A    return this%0A  %7D%0A%0A  build() /*: stream.Readable */ %7B%0A    const builder = this%0A    return new stream.Readable(%7B%0A      read: function() %7B%0A        if (builder.err) %7B%0A          this.emit('error', builder.err)%0A        %7D else %7B%0A          this.push(builder
 .dat
@@ -606,22 +606,26 @@
 ta)%0A    
-result
+      this
 .push(nu
@@ -632,26 +632,32 @@
 ll)%0A
-%0A    return result
+        %7D%0A      %7D%0A    %7D)
 %0A  %7D

Allow throwing errors