<commit_before>girder.models.FileModel = girder.Model.extend({
    resourceName: 'file',
    resumeInfo: null,

    /**
     * Upload into an existing file object (i.e. this model) to change its
     * contents. This does not change the name or MIME type of the existing
     * file.
     * @param data A browser File object, browser Blob object, or raw data to be uploaded.
     */
    updateContents: function (data) {
        if (_.isString(data)) {
            data = new Blob([data]);
        }

        this.upload(null, data, {
            path: 'file/' + this.get('_id') + '/contents',
            type: 'PUT',
            data: {
                size: data.size
            }
        });
    },

    /**
     * Upload data to a new file in a given container
     * @param Model A constructor for the parent model (either FolderModel or ItemModel).
     * @param model The parent model to upload to, or a string containing the id thereof.
     * @param data The data to upload - either a string, File object, or Blob object.
     * @param name The name of the file to create (optional if data is a File).
     * @param type The mime type of the file (optional).
     */
    _uploadToContainer: function (Model, model, data, name, type) {
        if (_.isString(model)) {
            model = new Model({
                _id: model
            });
        }

        if (_.isString(data)) {
            data = new Blob([data]);
            data.name = name;
            data.type = type;
        }

        this.upload(model, data);
    },

    /**
     * Upload data to a new file in a given folder
     * @param parentFolder The parent folder to upload to, or a string containing the id thereof.
     * @param data The data to upload - either a string, File object, or Blob object.
     * @param name The name of the file to create (optional if data is a File).
     * @param type The mime type of the file (optional).
     */
    uploadToFolder: function (parentFolder, data, name, type) {
        this._uploadToContainer(girder.models.FolderModel, parentFolder, data, name, type);
    },

    /**
     * Upload data to a new file in a given folder
     * @param parentItem The parent item to upload to, or a string containing the id thereof.
     * @param data The data to upload - either a string, File object, or Blob object.
     * @param name The name of the file to create (optional if data is a File).
     * @param type The mime type of the file (optional).
     */
    uploadToItem: function (parentItem, data, name, type) {<commit_msg>Improved and refactored argument handling for upload functions<commit_after>girder.models.FileModel = girder.Model.extend({
    resourceName: 'file',
    resumeInfo: null,

    _wrapData: function (data) {
        var datatype = data.toString(),
            wrapped = data;

        if (datatype !== "[object Blob]" && datatype !== "[object File]") {
            if (!_.isArray(data)) {
                wrapped = [data];
            }
            wrapped = new Blob(wrapped);
        }

        return wrapped;
    },

    /**
     * Upload into an existing file object (i.e. this model) to change its
     * contents. This does not change the name or MIME type of the existing
     * file.
     * @param data A browser File object, browser Blob object, or raw data to be uploaded.
     */
    updateContents: function (data) {
        data = this._wrapData(data);

        this.upload(null, data, {
            path: 'file/' + this.get('_id') + '/contents',
            type: 'PUT',
            data: {
                size: data.size
            }
        });
    },

    /**
     * Upload data to a new file in a given container
     * @param Model A constructor for the parent model (either FolderModel or ItemModel).
     * @param model The parent model to upload to, or a string containing the id thereof.
     * @param data The data to upload - either a string, File object, or Blob object.
     * @param name The name of the file to create (optional if data is a File).
     * @param type The mime type of the file (optional).
     */
    _uploadToContainer: function (Model, model, data, name, type) {
        var datatype = data.toString();

        if (_.isString(model)) {
            model = new Model({
                _id: model
            });
        }

        data = this._wrapData(data);
        data.name = name;
        data.type = type;

        this.upload(model, data);
    },

    /**
     * Upload data to a new file in a given folder
     * @param parentFolder The parent folder to upload to, or a string containing the id thereof.
     * @param data The data to upload - either a string, File object, or Blob object.
     * @param name The name of the file to create (optional if data is a File).
     * @param type The mime type of the file (optional).
     */
    uploadToFolder: function (parentFolder, data, name, type) {
        this._uploadToContainer(girder.models.FolderModel, parentFolder, data, name, type);
    },

    /**
     * Upload data to a new file in a given folder
     * @param parentItem The parent item to upload to, or a string containing the id thereof.
     * @param data The data to upload - either a string, File object, or Blob object.
     * @param name The name of the file to create (optional if data is a File).
     * @param type The mime type of the file (optional).
     */
    uploadToItem: function (parentItem, data, name, type) {
{'fraction_non_alphanumeric': 0.09629493763756419, 'fraction_numerical': 0.0, 'mean_word_length': 2.105353075170843, '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': '1193688', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1487, 'n_words': 646}