           performWrite()
   return stream
 
+exports.open = open
+
 if module is require.main
-  stream = create {logger: console}, (stream, webpage) ->
+  stream = open {logger: console}, (stream, webpage) ->
 
     # Right now, just echo back any data received to show that this is working.
     # TODO: use dnode?

      return value
  return "(#{func})(JSON.parse(#{JSON.stringify(optionsString)}))"

create = (options, bootstrap) ->
  logger = options?.logger or {}
  # TODO: just find an open port instead
  phantomServerPort = options?.phantomServerPort or PHANTOMJS_SERVER_PORT
  stdoutDataPrefix = "DATA#{Math.random().toString().slice(2)}:"
  phantomOptions =
    port: phantomServerPort
    stdoutDataPrefix: stdoutDataPrefix
    bootstrap: options?.bootstrap or bootstrap or options

  # Build a tempfile that contains our phantomjs script.
  temp.open {prefix: "phantomstream", suffix: ".js"}, (err, info) ->

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