           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) ->

      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
