<commit_before>package haxepunk.utils;

import flash.net.SharedObject;

/**
 * Static helper class used for saving and loading data from stored cookies.
 */
class Data
{
	public static var PREFIX:Null<String> = "HaxePunk";

	/**
	 * If you want to share data between different SWFs on the same host, use this id.
	 */
	public static var id:String = "";

	/**
	 * Overwrites the current data with the file.
	 * @param	file		The filename to load.
	 */
	public static function load(file:String = "")
	{
		var data:Dynamic = loadData(file);
		_data = new Map<String, Dynamic>();
		for (str in Reflect.fields(data)) _data.set(str, Reflect.field(data, str));
	}

	/**
	 * Overwrites the file with the current data. The current data will not be saved until this function is called.
	 * @param	file		The filename to save.
	 * @param	overwrite	Clear the file before saving.
	 */
	public static function save(file:String = "", overwrite:Bool = true)
	{
		if (_shared != null) _shared.clear();
		var data:Dynamic = loadData(file);
		var str:String;
		if (overwrite)
			for (str in Reflect.fields(data)) Reflect.deleteField(data, str);
		for (str in _data.keys()) Reflect.setField(data, str, _data.get(str));

#if js
		_shared.flush();
#else
		_shared.flush(SIZE);
#end
	}

	/**
	 * Reads an int from the current data.
	 * @param	name			Property to read.
	 * @param	defaultValue	Default value.
	 * @return	The property value, or defaultValue if the property is not assigned.
	 */
	public static function readInt(name:String, defaultValue:Int = 0):Int
	{
		return Std.int(read(name, defaultValue));
	}

	/**
	 * Reads a Boolean from the current data.
	 * @param	name			Property to read.
	 * @param	defaultValue	Default value.
	 * @return	The property value, or defaultValue if the property is not assigned.
	 */
	public static function readBool(name:String, defaultValue:Bool = true):Bool
	{
		return read(name, defaultValue);
	}

	/**
	 * Reads a String from the current data.
	 * @param	name			Property to read.
	 * @param	defaultValue	Default value.
	 * @return	The property value, or defaultValue if the property is not assigned.
	 */
	public static function readString(name:String, defaultValue:String = ""):String
	{
		return Std.string(read(name, defaultValue));
	}

	/**
	 * Reads a property from the data object.
	 * @param	name			Property to read.
	 * @param	defaultValue	Default value.
	 * @return	The property value, or defaultValue if the property is not assigned.
	 */
	public static function read(name:String, ?defaultValue:Dynamic):Dynamic
	{
		if (_data.get(name) != null) return _data.get(name);
		return defaultValue;
	}

	/**
	 * Writes a Dynamic object to the current data.
	 * @param	name		Property to write.
	 * @param	value		Value to write.
	 */
	public static function write(name:String, value:Dynamic)
	{
		_data.set(name, value);
	}

	/** @private Loads the data file, or return it if you're loading the same one. */
	static function loadData(file:String):Dynamic
	{
		if (file == null) file = DEFAULT_FILE;
		var p = (PREFIX == null ? "" : PREFIX + "/");
		if (id != "") _shared = SharedObject.getLocal('$p/$file', id);
		else _shared = SharedObject.getLocal('$p/$file');
		return _shared.data;
	}

	// Data information.
	static var _shared:SharedObject;
	static var _dir:String;
	static var _data:Map<String, Dynamic> = new Map<String, Dynamic>();
	static inline var DEFAULT_FILE:String = "_file";
	static inline var SIZE:Int = 10000;
}<commit_msg>Revert "Fix Data save path"<commit_after>package haxepunk.utils;

import flash.net.SharedObject;

/**
 * Static helper class used for saving and loading data from stored cookies.
 */
class Data
{
	public static var PREFIX:Null<String> = "HaxePunk";

	/**
	 * If you want to share data between different SWFs on the same host, use this id.
	 */
	public static var id:String = "";

	/**
	 * Overwrites the current data with the file.
	 * @param	file		The filename to load.
	 */
	public static function load(file:String = "")
	{
		var data:Dynamic = loadData(file);
		_data = new Map<String, Dynamic>();
		for (str in Reflect.fields(data)) _data.set(str, Reflect.field(data, str));
	}

	/**
	 * Overwrites the file with the current data. The current data will not be saved until this function is called.
	 * @param	file		The filename to save.
	 * @param	overwrite	Clear the file before saving.
	 */
	public static function save(file:String = "", overwrite:Bool = true)
	{
		if (_shared != null) _shared.clear();
		var data:Dynamic = loadData(file);
		var str:String;
		if (overwrite)
			for (str in Reflect.fields(data)) Reflect.deleteField(data, str);
		for (str in _data.keys()) Reflect.setField(data, str, _data.get(str));

#if js
		_shared.flush();
#else
		_shared.flush(SIZE);
#end
	}

	/**
	 * Reads an int from the current data.
	 * @param	name			Property to read.
	 * @param	defaultValue	Default value.
	 * @return	The property value, or defaultValue if the property is not assigned.
	 */
	public static function readInt(name:String, defaultValue:Int = 0):Int
	{
		return Std.int(read(name, defaultValue));
	}

	/**
	 * Reads a Boolean from the current data.
	 * @param	name			Property to read.
	 * @param	defaultValue	Default value.
	 * @return	The property value, or defaultValue if the property is not assigned.
	 */
	public static function readBool(name:String, defaultValue:Bool = true):Bool
	{
		return read(name, defaultValue);
	}

	/**
	 * Reads a String from the current data.
	 * @param	name			Property to read.
	 * @param	defaultValue	Default value.
	 * @return	The property value, or defaultValue if the property is not assigned.
	 */
	public static function readString(name:String, defaultValue:String = ""):String
	{
		return Std.string(read(name, defaultValue));
	}

	/**
	 * Reads a property from the data object.
	 * @param	name			Property to read.
	 * @param	defaultValue	Default value.
	 * @return	The property value, or defaultValue if the property is not assigned.
	 */
	public static function read(name:String, ?defaultValue:Dynamic):Dynamic
	{
		if (_data.get(name) != null) return _data.get(name);
		return defaultValue;
	}

	/**
	 * Writes a Dynamic object to the current data.
	 * @param	name		Property to write.
	 * @param	value		Value to write.
	 */
	public static function write(name:String, value:Dynamic)
	{
		_data.set(name, value);
	}

	/** @private Loads the data file, or return it if you're loading the same one. */
	static function loadData(file:String):Dynamic
	{
		if (file == null) file = DEFAULT_FILE;
		var p = (PREFIX == null ? "" : PREFIX + "/");
		if (id != "") _shared = SharedObject.getLocal('$p$id/$file', "/");
		else _shared = SharedObject.getLocal('$p$file');
		return _shared.data;
	}

	// Data information.
	static var _shared:SharedObject;
	static var _dir:String;
	static var _data:Map<String, Dynamic> = new Map<String, Dynamic>();
	static inline var DEFAULT_FILE:String = "_file";
	static inline var SIZE:Int = 10000;
}
{'fraction_non_alphanumeric': 0.11850251979841613, 'fraction_numerical': 0.0017278617710583153, 'mean_word_length': 3.7348329925017043, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '956909', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2155, 'n_words': 763}