<commit_before>/**
 * Module dependencies.
 */

var Emitter = require('emitter');

/**
 * Expose `Submit`.
 */

module.exports = Submit;

/**
 * Initialize a new `Submit` file`.
 * This represents a single file upload.
 *
 * Events:
 *
 *   - `error` an error occurred
 *   - `abort` upload was aborted
 *   - `progress` upload in progress (`e.percent` etc)
 *   - `end` upload is complete
 *
 * @param {File} file
 * @api private
 */

function Submit(form) {
  if (!(this instanceof Submit)) return new Submit(file);
  Emitter.call(this);
  this.form = form;
}

/**
 * Mixin emitter.
 */

Emitter(Submit.prototype);

/**
 * Submit to the given `path`.
 *
 * @param {String} path
 * @api public
 */

Submit.prototype.to = function(path){
  // TODO: x-browser
  var req = this.req = new XMLHttpRequest;
  req.open('POST', path);
  req.onload = this.onload.bind(this);
  req.onerror = this.onerror.bind(this);
  req.upload.onprogress = this.onprogress.bind(this);
  req.send(form);
};

/**
 * Abort the XHR.
 *
 * @api public
 */

Submit.prototype.abort = function(){
  this.emit('abort');
  this.req.abort();
};

/**
 * Error handler.
 *
 * @api private
 */

Submit.prototype.onerror = function(e){
  this.emit('error', e);
};

/**
 * Onload handler.
 *
 * @api private
 */
<commit_msg>form should be `this.form`<commit_after>/**
 * Module dependencies.
 */

var Emitter = require('emitter');

/**
 * Expose `Submit`.
 */

module.exports = Submit;

/**
 * Initialize a new `Submit` file`.
 * This represents a single file upload.
 *
 * Events:
 *
 *   - `error` an error occurred
 *   - `abort` upload was aborted
 *   - `progress` upload in progress (`e.percent` etc)
 *   - `end` upload is complete
 *
 * @param {File} file
 * @api private
 */

function Submit(form) {
  if (!(this instanceof Submit)) return new Submit(file);
  Emitter.call(this);
  this.form = form;
}

/**
 * Mixin emitter.
 */

Emitter(Submit.prototype);

/**
 * Submit to the given `path`.
 *
 * @param {String} path
 * @api public
 */

Submit.prototype.to = function(path){
  // TODO: x-browser
  var req = this.req = new XMLHttpRequest;
  req.open('POST', path);
  req.onload = this.onload.bind(this);
  req.onerror = this.onerror.bind(this);
  req.upload.onprogress = this.onprogress.bind(this);
  req.send(this.form);
};

/**
 * Abort the XHR.
 *
 * @api public
 */

Submit.prototype.abort = function(){
  this.emit('abort');
  this.req.abort();
};

/**
 * Error handler.
 *
 * @api private
 */

Submit.prototype.onerror = function(e){
  this.emit('error', e);
};

/**
 * Onload handler.
 *
 * @api private
 */

{'fraction_non_alphanumeric': 0.18006182380216385, 'fraction_numerical': 0.0, 'mean_word_length': 3.0453125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3029519', 'n_tokens_mistral': 916, 'n_tokens_neox': 915, 'n_words': 221}