text: var Transform = require('stream').Transform;
  var extend = require('util')._extend;
  var request = require('hyperquest');
  var querystring = require('querystring');
  var nlJSON = require('newline-json');
  
  module.exports = ResultStream;
  function ResultStream(jobId, defaultReqOpts, options) {
    return function resultStream (reqOpts) {
      if (!reqOpts)
        reqOpts = {};
  
      var url = options.baseUrl +
                encodeURIComponent(jobId) +
                '/results?' +
                querystring.stringify(reqOpts);
  
      var opts = extend({
        uri: url
      }, defaultReqOpts);
  
      var req = request(opts);
      req.on('response', checkStatus);
      function checkStatus() {
        var status = req.response.statusCode;
        // 0 means client canceled on the browser
        if (status !== 200 && status !== 0) {
          var err = new Error('Unexpected status code: ' + status);
          err.status = status;
          throw err;
        }
      }
  
      var parser = new nlJSON.Parser();
      req.pipe(parser);
  
      parser.on('end', function() {
        req.end();
      });
  
      return parser;
    };
  }
  