<commit_before>/**
 * mule-upload.js
 *
 * Copyright 2012-2013, <NAME>
 * Released under GPL License.
 * License: http://www.gnu.org/copyleft/gpl.html
 */

function mule_upload(settings) {
    var debug = true;

    // custom logging function that prepends a text for easy identification;
    // it is also toggled by the `debug` flag
    var log = function() {};
    if(debug && console && console.log) {
        log = function() {
            var args = ["[MuleUploader]"];
            for(var i=0; i<arguments.length; i++) {
                args.push(arguments[i]);
            }
            return console.log.apply(console, args);
        };
    }

    // AJAX helper. It takes an object that contains load_callback, error_callback,
    // url, method, headers, state_change_callback, progress_callback
    var XHR = function(args) {
        // the user may not pass any headers
        args.headers = args.headers || {};

        // if no method is given, default to GET
        args.method = args.method || "GET";

        var xhr = new XMLHttpRequest();
        // set the "load" callback if given
        if(args.load_callback && typeof args.load_callback == 'function') {
            xhr.addEventListener("load", args.load_callback, true);
        }

        // set the "error" callback if given
        if(args.error_callback && typeof args.error_callback == 'function') {
            xhr.addEventListener("error", args.error_callback, true);
        }

        // set the "readystatechange" callback if given
        if(args.state_change_callback && typeof args.state_change_callback == 'function') {
            xhr.addEventListener("readystatechange", args.state_change_callback);
        }

        // set the "progress" callback if given
        if(args.progress_callback && typeof args.progress_callback == 'function') {
            xhr.upload.addEventListener("progress", args.progress_callback);
        }

        // set the "timeout" callback if given
        if(args.timeout_callback && typeof args.timeout_callback == 'function') {
            xhr.addEventListener('timeout', timeout_callback);
        }

        // open the xhr connection
        xhr.open(args.method, args.url);

        // set the headers
        for(var header in args.headers) {
            xhr.setRequestHeader(header, args.headers[header]);
        }

        // send the ajax call
        if(args.body) {
            xhr.send(args.body);
        } else {
            xhr.send();
        }
        return xhr;
    };

    // helper constants for more readable code
    var KB = 1024;
    var MB = 1024 * KB;
    var GB = 1024 * MB;

    // for new webkit browsers, the .slice() method is named .webkitSlice()
    // similar for mozilla
    File.prototype.slice = File.prototype.webkitSlice || File.prototype.mozSlice || File.prototype.slice;

    // verify that the browser has the needed HTML5 capabilities
    if(!(window.File && window.FileList && window.Blob)) {
        return -1;
    }
    if(navigator.userAgent.indexOf("Firefox") !== -1) {
        try {
            new Blob(["something"]);
        } catch(e) {
            return -1;
        }
    }
    log("OK");

    function Uploader(settings) {
        // `u` is often used as an alias for `this` to be used in nested closures
        var u = this;

        settings = settings || {};

        // make the input element another possible setting
        // in some cases (e.g. drag & drop) there is no input element
        u.input = settings.file_input;
        u.file  = settings.file;

        // NOTE: For Amazon S3, the minimum chunk size is 5MB
        // we are using 6 for safe measure. Note that the maximum number of chunks
        // is 10,000, so for example, if the chunk size is 6MB, the maximum
        // possible file size is 6MB * 10,000 = ~58GB
        settings.chunk_size = settings.chunk_size || (6 * MB); // default 6MB
        settings.max_size = settings.max_size || 50 * (1 << 30); // 5GB

        // the number of parallel upload xhr's
        settings.num_workers = settings.num_workers || 3;

        // the S3 object key; I recommend to generate this dynamically (e.g.
        // a random string) to avoid unwanted overwrites.
        settings.key = settings.key || "the_key";

        // the Amazon S3 bucket where you'll store the uploads
        settings.bucket = settings.bucket;
        settings.host = settings.host || "https://" + settings.bucket + ".s3.amazonaws.com";

        // the Amazon S3 access key. DO NOT give the AWS Secret code!
        settings.access_key = settings.access_key;

        // the Mime-Type of the content. You must match this with the backend value
        // or you'll get an Invalid Signature error. If unsure about the
        // mime type, use application/octet-stream
        settings.content_type = settings.content_type || "application/octet-stream";


        // acl can be set to:
        // private
        // public-read (* default)
        // public-read-write
        // authenticated-read
        // bucket-owner-read
        // bucket-owner-full-control<commit_msg>update the script to use http or https based on current window or protocol setting<commit_after>/**
 * mule-upload.js
 *
 * Copyright 2012-2013, <NAME>
 * Released under GPL License.
 * License: http://www.gnu.org/copyleft/gpl.html
 */

function mule_upload(settings) {
    var debug = true;

    // custom logging function that prepends a text for easy identification;
    // it is also toggled by the `debug` flag
    var log = function() {};
    if(debug && console && console.log) {
        log = function() {
            var args = ["[MuleUploader]"];
            for(var i=0; i<arguments.length; i++) {
                args.push(arguments[i]);
            }
            return console.log.apply(console, args);
        };
    }

    // AJAX helper. It takes an object that contains load_callback, error_callback,
    // url, method, headers, state_change_callback, progress_callback
    var XHR = function(args) {
        // the user may not pass any headers
        args.headers = args.headers || {};

        // if no method is given, default to GET
        args.method = args.method || "GET";

        var xhr = new XMLHttpRequest();
        // set the "load" callback if given
        if(args.load_callback && typeof args.load_callback == 'function') {
            xhr.addEventListener("load", args.load_callback, true);
        }

        // set the "error" callback if given
        if(args.error_callback && typeof args.error_callback == 'function') {
            xhr.addEventListener("error", args.error_callback, true);
        }

        // set the "readystatechange" callback if given
        if(args.state_change_callback && typeof args.state_change_callback == 'function') {
            xhr.addEventListener("readystatechange", args.state_change_callback);
        }

        // set the "progress" callback if given
        if(args.progress_callback && typeof args.progress_callback == 'function') {
            xhr.upload.addEventListener("progress", args.progress_callback);
        }

        // set the "timeout" callback if given
        if(args.timeout_callback && typeof args.timeout_callback == 'function') {
            xhr.addEventListener('timeout', timeout_callback);
        }

        // open the xhr connection
        xhr.open(args.method, args.url);

        // set the headers
        for(var header in args.headers) {
            xhr.setRequestHeader(header, args.headers[header]);
        }

        // send the ajax call
        if(args.body) {
            xhr.send(args.body);
        } else {
            xhr.send();
        }
        return xhr;
    };

    // helper constants for more readable code
    var KB = 1024;
    var MB = 1024 * KB;
    var GB = 1024 * MB;

    // for new webkit browsers, the .slice() method is named .webkitSlice()
    // similar for mozilla
    File.prototype.slice = File.prototype.webkitSlice || File.prototype.mozSlice || File.prototype.slice;

    // verify that the browser has the needed HTML5 capabilities
    if(!(window.File && window.FileList && window.Blob)) {
        return -1;
    }
    if(navigator.userAgent.indexOf("Firefox") !== -1) {
        try {
            new Blob(["something"]);
        } catch(e) {
            return -1;
        }
    }
    log("OK");

    function Uploader(settings) {
        // `u` is often used as an alias for `this` to be used in nested closures
        var u = this;

        settings = settings || {};

        // make the input element another possible setting
        // in some cases (e.g. drag & drop) there is no input element
        u.input = settings.file_input;
        u.file  = settings.file;

        // NOTE: For Amazon S3, the minimum chunk size is 5MB
        // we are using 6 for safe measure. Note that the maximum number of chunks
        // is 10,000, so for example, if the chunk size is 6MB, the maximum
        // possible file size is 6MB * 10,000 = ~58GB
        settings.chunk_size = settings.chunk_size || (6 * MB); // default 6MB
        settings.max_size = settings.max_size || 50 * (1 << 30); // 5GB

        // the number of parallel upload xhr's
        settings.num_workers = settings.num_workers || 3;

        // the S3 object key; I recommend to generate this dynamically (e.g.
        // a random string) to avoid unwanted overwrites.
        settings.key = settings.key || "the_key";

        // the Amazon S3 bucket where you'll store the uploads
        settings.bucket = settings.bucket;
        settings.protocol = settings.protocol || window.location.protocol || "http:";
        settings.host = settings.host || settings.protocol + "//" + settings.bucket + ".s3.amazonaws.com";

        // the Amazon S3 access key. DO NOT give the AWS Secret code!
        settings.access_key = settings.access_key;

        // the Mime-Type of the content. You must match this with the backend value
        // or you'll get an Invalid Signature error. If unsure about the
        // mime type, use application/octet-stream
        settings.content_type = settings.content_type || "application/octet-stream";


        // acl can be set to:
        // private
        // public-read (* default)
        // public-read-write
        // authenticated-read
        // bucket-owner-read
        // bucket-owner-full-control
{'fraction_non_alphanumeric': 0.11214953271028037, 'fraction_numerical': 0.010598323537913094, 'mean_word_length': 2.084695393759287, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '4428070', 'n_tokens_mistral': 2968, 'n_tokens_neox': 2795, 'n_words': 901}