| 6400 | } |
| 6401 | |
| 6402 | function XhrReceiver(url, AjaxObject) { |
| 6403 | debug(url); |
| 6404 | EventEmitter.call(this); |
| 6405 | var self = this; |
| 6406 | |
| 6407 | this.bufferPosition = 0; |
| 6408 | |
| 6409 | this.xo = new AjaxObject('POST', url, null); |
| 6410 | this.xo.on('chunk', this._chunkHandler.bind(this)); |
| 6411 | this.xo.once('finish', function(status, text) { |
| 6412 | debug('finish', status, text); |
| 6413 | self._chunkHandler(status, text); |
| 6414 | self.xo = null; |
| 6415 | var reason = status === 200 ? 'network' : 'permanent'; |
| 6416 | debug('close', reason); |
| 6417 | self.emit('close', null, reason); |
| 6418 | self._cleanup(); |
| 6419 | }); |
| 6420 | } |
| 6421 | |
| 6422 | inherits(XhrReceiver, EventEmitter); |
| 6423 | |