     on: (event, callback)->
       if event is "data"
         emitter.on "data", (buffer) ->
+          # TODO: implement real encoding
           if encoding
             callback(buffer.toString())
           else

          performWrite()
  return stream

if module is require.main
  stream = create {logger: console}, (stream, webpage) ->

    # Right now, just echo back any data received to show that this is working.
    # TODO: use dnode?

      res.close()

    # Pass the stream to the bootstrap script.
    # TODO: shadow all globals to force explicit use of window object
    bootstrap = new Function("(#{options.bootstrap}).apply({}, arguments)")
    bootstrap(stream, phantom, require, window)

    # Indicate to node that the phantomjs process is ready by writing
    # some data to it.
    stream.write("READY")

  # Serialize the options for `func`, which will be stringified and opened
