DataFile by FFGFlash
A simple data storage solution, DataFile automatically backsup any and all datafiles for minimal losses.
Initializing
To initialize the DataFile you must provide it with a root directory.
const DataFile = "Put your root directory here (typically '__dirname')";
Creating a DataFile
To create a DataFile you must provide it with a name.
const example = "example";
Though you can also provide extra options to modify how your DataFile behaves.
const example = "example" auto_save: 500 // The delay between autosaves, by default autosaving is turned off. debug: true // If toggled on then the DataFile will log debug information to the console, by default this is turned off (Warning: Can become quite overwhelming) structure: test: 0 // This determines the default structure for the DataFile, this only affects the file the first time it is created and by default it is '{}';
Loading a DataFile
This will attempt to load the data from the main data file, if that fails it'll attempt the backup file, and finally it will start from the structure it was provided.
example; example;
Saving a DataFile
This will attempt to save the data to the main data file, followed by the backup file, but only if the first is successful (to prevent data loss).
example; example;
Error Handling
Some examples of error handling, for saving and loading.
example; example; example;
Manipulating the DataFile
When designed this was very important, trying to make this as simple and easy to manipulate as possible. (This example also demonstrates a manual auto-saving system.)
const example = "example" structure: saves: 0 ;example;example;
Example
A simple example demonstrating most of the things mentioned above.
const DataFile = __dirname;const Example = "example" auto_save: 500 debug: true structure: data1: false data2: "example_data" data3: 107 ; Example;