<commit_before>/*
 * tus-jquery-client
 * https://github.com/tus/tus-jquery-client
 *
 * Copyright (c) 2013 Transloadit Ltd and Contributors
 * http://tus.io/
 *
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/MIT
 */

(function ($) {
  'use strict';

  // The Public API
  var tus = window.tus = {
    upload: function(file, options) {
      var upload = new ResumableUpload(file, options);
      upload._start();
      return upload;
    },
  };

  function ResumableUpload(file, options) {
    // The file to upload
    this.file = file;
    // Options for resumable file uploads
    this.options = {
      // The tus upload endpoint url
      endpoint: options.endpoint,
    };

    // The url of the uploaded file, assigned by the tus upload endpoint
    this.url = null;
    // Bytes sent to the server so far
    this.bytesUploaded = null;
    // Total amount of bytes to sent
    this.bytesTotal = null;

    // Create a deferred and make our upload a promise object
    this._deferred = $.Deferred();
    this._deferred.promise(this);
  }

  // Creates a file resource at the configured tus endpoint and gets the url for it.
  ResumableUpload.prototype._start = function() {
    var self = this;
    var options = {
      type: 'POST',
      url: this.options.endpoint,
      headers: {
        'Content-Range': 'bytes */' + this.file.size,
        'Content-Disposition': 'attachment; filename="' + encodeURI(this.file.name) + '"'
      }
    };

    this.bytesUploaded = 0;
    this.bytesTotal = this.file.size;

    $.ajax(options)
      .fail(function(jqXHR, textStatus, errorThrown) {
        // @TODO: Implement retry support
        self._deferred.reject(new Error('Could not create file resource: ' + textStatus), jqXHR, errorThrown);
      })
      .done(function(data, textStatus, jqXHR) {
        self.url = jqXHR.getResponseHeader('Location');
        if (!self.url) {
          self._deferred.reject(new Error('Could not get url for file resource: ' + textStatus));
          return;
        }

        // We now have a url, time to fire the progress event!
        self._deferred.notifyWith(self);
        self._upload();
      });
  };

  // Uploads the file data to tus resource url created by _start()
  ResumableUpload.prototype._upload = function() {
    var self = this;
    var slice = this.file.slice || this.file.webkitSlice || this.file.mozSlice;
    var blob = slice.call(this.file, 0, this.file.size, this.file.type);
    var xhr = $.ajaxSettings.xhr();

    var options = {
      type: 'PUT',
      url: this.url,
      data: blob,
      processData: false,
      contentType: this.file.type,
      cache: false,
      xhr: function() { return xhr },
      headers: {
        'Content-Range': 'bytes 0-' + (this.file.size - 1)  + '/' + this.file.size,
      }
    };
<commit_msg>Whitespace<commit_after>/*
 * tus-jquery-client
 * https://github.com/tus/tus-jquery-client
 *
 * Copyright (c) 2013 Transloadit Ltd and Contributors
 * http://tus.io/
 *
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/MIT
 */

(function ($) {
  'use strict';

  // The Public API
  var tus = window.tus = {
    upload: function(file, options) {
      var upload = new ResumableUpload(file, options);
      upload._start();
      return upload;
    },
  };

  function ResumableUpload(file, options) {
    // The file to upload
    this.file = file;
    // Options for resumable file uploads
    this.options = {
      // The tus upload endpoint url
      endpoint: options.endpoint,
    };

    // The url of the uploaded file, assigned by the tus upload endpoint
    this.url = null;
    // Bytes sent to the server so far
    this.bytesUploaded = null;
    // Total amount of bytes to sent
    this.bytesTotal = null;

    // Create a deferred and make our upload a promise object
    this._deferred = $.Deferred();
    this._deferred.promise(this);
  }

  // Creates a file resource at the configured tus endpoint and gets the url for it.
  ResumableUpload.prototype._start = function() {
    var self = this;
    var options = {
      type: 'POST',
      url: this.options.endpoint,
      headers: {
        'Content-Range': 'bytes */' + this.file.size,
        'Content-Disposition': 'attachment; filename="' + encodeURI(this.file.name) + '"'
      }
    };

    this.bytesUploaded = 0;
    this.bytesTotal = this.file.size;

    $.ajax(options)
      .fail(function(jqXHR, textStatus, errorThrown) {
        // @TODO: Implement retry support
        self._deferred.reject(new Error('Could not create file resource: ' + textStatus), jqXHR, errorThrown);
      })
      .done(function(data, textStatus, jqXHR) {
        self.url = jqXHR.getResponseHeader('Location');
        if (!self.url) {
          self._deferred.reject(new Error('Could not get url for file resource: ' + textStatus));
          return;
        }

        // We now have a url, time to fire the progress event!
        self._deferred.notifyWith(self);
        self._upload();
      });
  };

  // Uploads the file data to tus resource url created by _start()
  ResumableUpload.prototype._upload = function() {
    var self  = this;
    var slice = this.file.slice || this.file.webkitSlice || this.file.mozSlice;
    var blob  = slice.call(this.file, 0, this.file.size, this.file.type);
    var xhr   = $.ajaxSettings.xhr();

    var options = {
      type: 'PUT',
      url: this.url,
      data: blob,
      processData: false,
      contentType: this.file.type,
      cache: false,
      xhr: function() { return xhr },
      headers: {
        'Content-Range': 'bytes 0-' + (this.file.size - 1)  + '/' + this.file.size,
      }
    };

{'fraction_non_alphanumeric': 0.1285437577038211, 'fraction_numerical': 0.002817397429124846, 'mean_word_length': 2.3789411064842354, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '3550755', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1745, 'n_words': 486}