<commit_before>/**
 * A library to manage files.
 * @author $imon
 * @since 1.0alpha1
 */

/**
 *  Base64 encode / decode
 *  http://www.webtoolkit.info/
 **/
Webos.base64 = {
	/**
	 * @private
	 */
	_keyStr : "<KEY>
 
	/**
	 * Encode a string to base64.
	 * @param {String} input The string to encode.
	 * @returns {String} The base64-encoded string.
	 */
	encode: function (input) {
		if (window.btoa) {
			return window.btoa(unescape(encodeURIComponent(input)));
		}

		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	/**
	 * Decode a base64-string.
	 * @param {String} input The base64-encoded string.
	 * @returns {String} The decoded string.
	 */
	decode: function (input) {
		if (window.atob) {
			return decodeURIComponent(escape(window.atob(input)));
		}

		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		return output;
	},
 
	// method for UTF-8 encoding
	utf8Encode: function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// method for UTF-8 decoding
	utf8Decode: function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
};

/**
 * A file.
 * @param {Object} data The file's data.
 * @constructor
 * @augments {Webos.Model}
 * @since 1.0alpha1
 * @example
 * //Listing files in the user's home folder
 * W.File.listDir('~', [function(files) { //We want to list files in the home folder (which is "~")
 *    var list = 'Files : ';
 *    for (var i = 0; i < files.length; i++) { //For each file
 *       var file = files[i];
 *       list += ' '+file.get('basename'); //Add the file to the list
 *    }
 *    alert(list); //Show the list
 * }, function(response) { //An error occured
 *    response.triggerError('Cannot list files in folder');
 * }]);
 */
Webos.File = function WFile(data) {
	Webos.Model.call(this, data); //Inherits from Webos.Model
};
Webos.File.prototype = {
	/**
	 * Update file's data, and complete automatically missing data.
	 * @param {Object} data The new data.
	 */
	hydrate: function(data) {
		var path = (data.path || this.get('path'));
		if (path) {
			if (!data.dirname) { //On définit automatiquement le dossier parent si non présent
				if (path.indexOf('/', 1) != -1) {
					data.dirname = path.replace(/\/[^\/]*\/?$/, '');
				} else if (path.indexOf('/') == 0) {
					data.dirname = '/';
				}
			}
			if (!data.basename) { //On définit automatiquement le nom du fichier si non présent
				data.basename = path.replace(/^.*[\/\\]/g, '');
			}
			if (data.is_dir === false && !data.extension) { //On définit automatiquement l'extension du fichier si non présent et que le fichier n'est pas un dossier
				data.extension = (/\./.test(path)) ? /[^.]+$/.exec(path)[0] : '';
			}
		}

		if (typeof data.is_binary == 'undefined') {
			if (data.mime_type) {
				data.is_binary = (data.mime_type.indexOf('text/') != 0);
			} else if (!this.exists('is_binary')) {
				data.is_binary = true;
			}
		}

		if (typeof data.labels == 'undefined') {
			data.labels = {};
		}
		if (!data.labels.hidden) {
			data.labels.hidden = (data.basename.charAt(0) == '.');
		}
		if (typeof data.labels.trashed == 'undefined') {
			data.labels.trashed = false;
		}

		return Webos.Model.prototype.hydrate.call(this, data);
	},
	/**
	 * Update file's data.
	 * @param {Object} data The new data.
	 * @private
	 */<commit_msg>Fixes issues with upper case extensions. Fixes #236.<commit_after>/**
 * A library to manage files.
 * @author $imon
 * @since 1.0alpha1
 */

/**
 *  Base64 encode / decode
 *  http://www.webtoolkit.info/
 **/
Webos.base64 = {
	/**
	 * @private
	 */
	_keyStr : "<KEY>
 
	/**
	 * Encode a string to base64.
	 * @param {String} input The string to encode.
	 * @returns {String} The base64-encoded string.
	 */
	encode: function (input) {
		if (window.btoa) {
			return window.btoa(unescape(encodeURIComponent(input)));
		}

		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	/**
	 * Decode a base64-string.
	 * @param {String} input The base64-encoded string.
	 * @returns {String} The decoded string.
	 */
	decode: function (input) {
		if (window.atob) {
			return decodeURIComponent(escape(window.atob(input)));
		}

		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		return output;
	},
 
	// method for UTF-8 encoding
	utf8Encode: function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// method for UTF-8 decoding
	utf8Decode: function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
};

/**
 * A file.
 * @param {Object} data The file's data.
 * @constructor
 * @augments {Webos.Model}
 * @since 1.0alpha1
 * @example
 * //Listing files in the user's home folder
 * W.File.listDir('~', [function(files) { //We want to list files in the home folder (which is "~")
 *    var list = 'Files : ';
 *    for (var i = 0; i < files.length; i++) { //For each file
 *       var file = files[i];
 *       list += ' '+file.get('basename'); //Add the file to the list
 *    }
 *    alert(list); //Show the list
 * }, function(response) { //An error occured
 *    response.triggerError('Cannot list files in folder');
 * }]);
 */
Webos.File = function WFile(data) {
	Webos.Model.call(this, data); //Inherits from Webos.Model
};
Webos.File.prototype = {
	/**
	 * Update file's data, and complete automatically missing data.
	 * @param {Object} data The new data.
	 */
	hydrate: function(data) {
		var path = (data.path || this.get('path'));
		if (path) {
			if (!data.dirname) { //On définit automatiquement le dossier parent si non présent
				if (path.indexOf('/', 1) != -1) {
					data.dirname = path.replace(/\/[^\/]*\/?$/, '');
				} else if (path.indexOf('/') == 0) {
					data.dirname = '/';
				}
			}
			if (!data.basename) { //On définit automatiquement le nom du fichier si non présent
				data.basename = path.replace(/^.*[\/\\]/g, '');
			}
			if (data.is_dir === false && !data.extension) { //On définit automatiquement l'extension du fichier si non présent et que le fichier n'est pas un dossier
				data.extension = (/\./.test(path)) ? /[^.]+$/.exec(path)[0] : '';
			}
			if (data.extension) { //On met l'extension en minuscules
				data.extension = data.extension.toLowerCase();
			}
		}

		if (typeof data.is_binary == 'undefined') {
			if (data.mime_type) {
				data.is_binary = (data.mime_type.indexOf('text/') != 0);
			} else if (!this.exists('is_binary')) {
				data.is_binary = true;
			}
		}

		if (typeof data.labels == 'undefined') {
			data.labels = {};
		}
		if (!data.labels.hidden) {
			data.labels.hidden = (data.basename.charAt(0) == '.');
		}
		if (typeof data.labels.trashed == 'undefined') {
			data.labels.trashed = false;
		}

		return Webos.Model.prototype.hydrate.call(this, data);
	},
	/**
	 * Update file's data.
	 * @param {Object} data The new data.
	 * @private
	 */
{'fraction_non_alphanumeric': 0.1906722764300421, 'fraction_numerical': 0.03374809775311073, 'mean_word_length': 2.6131953428201813, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 41, 'https://': 0, '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': '571411', 'n_tokens_mistral': 5041, 'n_tokens_neox': 4228, 'n_words': 1018}