Class: SaveFile

DKTools.IO.SaveFile

Save file class

new DKTools.IO.SaveFile ()

Extends

Members

_extension String privatereadonly inherited

_initialExtension String privatereadonly inherited

_name String privatereadonly inherited

_path String privatereadonly inherited

extension inherited

Gets extension of the entity

initialExtension inherited

Gets initial extension of the entity

name inherited

Gets name of the entity

path inherited

Gets path of the entity

Methods

__processError (error, onError) private inherited

Name Type Description
error * Error
onError function optional Callback function upon completion of an operation with error

_detectExtension () private inherited

Detects the extension

copy (destination, object)Number inherited

Copies file Returns a code of the result of an operation Possible results: DKTools.IO.OK DKTools.IO.EXPECT_CALLBACK DKTools.IO.ERROR_NOT_LOCAL_MODE DKTools.IO.ERROR_PATH_DOES_NOT_EXIST DKTools.IO.ERROR_OPTIONS_ARE_NOT_AVAILABLE
Name Type Description
destination String Destination filename of the copy operation
object Object Options of an operation
Name Type Description
sync Boolean optional Use synchronous version of FileSystem.copyFile
createDirectory Boolean | Object optional Create a directory for the file
flags Number optional Modifiers for copy operation
onSuccess function optional Callback function upon completion of an operation (only for object.sync == false)
onError function optional Callback function upon completion of an operation with error (only for object.sync == false)
createDirectory.options Object optional Options for FileSystem.mkdir or FileSystem.mkdirSync
Name Type Description
recursive Boolean optional Parent folders should be created
mode Number | String optional Directory permission
Returns:
Type Description
Number Code of the result of an operation

copyAsync (destination, object)Promise.<Number> async inherited

Copies file Asynchronous version of DKTools.IO.File.prototype.copy Promise resolves a code of the result of an operation Possible results: DKTools.IO.OK DKTools.IO.ERROR_NOT_LOCAL_MODE DKTools.IO.ERROR_PATH_DOES_NOT_EXIST
Name Type Default Description
destination String Destination filename of the copy operation
object Object {} optional Options of an operation
Name Type Description
createDirectory Boolean | Object optional Create a directory for the file
flags Number optional Modifiers for copy operation
createDirectory.options Object optional Options for FileSystem.mkdir or FileSystem.mkdirSync
Name Type Description
recursive Boolean optional Parent folders should be created
mode Number | String optional Directory permission
Returns:
Type Description
Promise.<Number> Code of the result of an operation

equals (entity)Boolean inherited

Returns true is the entity is same
Name Type Description
entity DKTools.IO.Entity Entity
Since:
  • 1.3.2
Returns:
Type Description
Boolean Entity is same

exists ()Boolean inherited

Returns true if the entity exists
Returns:
Type Description
Boolean Entity exists

getAbsolutePath ()String inherited

Returns the absolute path
Returns:
Type Description
String Absolute path
Returns the directory of the file
Returns:
Type Description
DKTools.IO.Directory Directory of the file

getDirectoryName ()String inherited

Returns the directory name
Returns:
Type Description
String Directory name

getFullName ()String inherited

Returns the full name
Version:
  • 1.2.0
Returns:
Type Description
String Full name

getFullPath ()String inherited

Returns the full path
Returns:
Type Description
String Full Path

getName ()String inherited

Returns the name of the entity without an extension
Returns:
Type Description
String Name of the entity without an extension

getPath ()String inherited

Returns the path
Returns:
Type Description
String Path

getStats (object)Object inherited

Returns a stats Returns an object with 2 properties: status - Result of an operation data - Loaded data if the status is not equal to DKTools.IO.OK then data will be null Possible statuses: DKTools.IO.OK DKTools.IO.EXPECT_CALLBACK DKTools.IO.ERROR_NOT_LOCAL_MODE DKTools.IO.ERROR_PATH_DOES_NOT_EXIST DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE DKTools.IO.ERROR_OPTIONS_ARE_NOT_AVAILABLE
Name Type Description
object Object Options of an operation
Name Type Description
sync Boolean optional Use synchronous version of stat
onSuccess function optional Callback function upon completion of an operation (only for object.sync == false)
onError function optional Callback function upon completion of an operation with error (only for object.sync == false)
Returns:
Type Description
Object Loaded stats

getStatsAsync ()Promise.<Object> async inherited

Returns a stats Asynchronous version of DKTools.IO.Entity.prototype.getStats Promise resolves an object with 2 properties: status - Result of an operation data - Loaded data if the status is not equal to DKTools.IO.OK then data will be null Possible statuses: DKTools.IO.OK DKTools.IO.ERROR_NOT_LOCAL_MODE DKTools.IO.ERROR_PATH_DOES_NOT_EXIST
Returns:
Type Description
Promise.<Object> Loaded stats

hasExtension ()Boolean inherited

Returns true if the entity has an extension
Returns:
Type Description
Boolean Entity has an extension

isAudio ()Boolean inherited

Returns true if an extension of the file is equal to .ogg or .ogg_
Returns:
Type Description
Boolean Extension of the file is equal to .ogg or .ogg_

isDirectory ()Boolean inherited

Returns true if the entity is a directory
Returns:
Type Description
Boolean Entity is a directory

isFile ()Boolean inherited

Returns true if the entity is a file
Returns:
Type Description
Boolean Entity is a file

isImage ()Boolean inherited

Returns true if an extension of the file is equal to .png, .png_ or .webp
Returns:
Type Description
Boolean Extension of the file is equal to .png, .png_ or .webp

isJson ()Boolean inherited

Returns true if an extension of the file is equal to .json
Returns:
Type Description
Boolean Extension of the file is equal to .json

isSave ()Boolean inherited

Returns true if an extension of the file is equal to .rmmzsave
Returns:
Type Description
Boolean Extension of the file is equal to .rmmzsave

isTexture ()Boolean inherited

Returns true if an extension of the file is equal to .dds
Since:
  • 1.1.0
Returns:
Type Description
Boolean Extension of the file is equal to .dds

isTxt ()Boolean inherited

Returns true if an extension of the file is equal to .txt
Returns:
Type Description
Boolean Extension of the file is equal to .txt

isVideo ()Boolean inherited

Returns true if an extension of the file is equal to .mp4 or .webm
Returns:
Type Description
Boolean Extension of the file is equal to .mp4 or .webm

load (object)Object inherited

Loads and returns a data Returns an object with 3 properties: status - Result of an operation data - Loaded data error - Error of an operation if the status is not equal to DKTools.IO.OK then data will be null Possible statuses: DKTools.IO.OK DKTools.IO.EXPECT_CALLBACK DKTools.IO.ERROR_PATH_DOES_NOT_EXIST DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE DKTools.IO.ERROR_OPTIONS_ARE_NOT_AVAILABLE DKTools.IO.ERROR_DECOMPRESSING_DATA DKTools.IO.ERROR_PARSING_DATA
Name Type Description
object Object Options of an operation
Name Type Description
sync Boolean optional Use synchronous version of FileSystem.readFile
options String | Object optional Options for FileSystem.readFile or FileSystem.readFileSync
onSuccess function optional Callback function upon completion of an operation (only for object.sync == false)
onError function optional Callback function upon completion of an operation with error (only for object.sync == false)
decompress Boolean optional Use LZString.decompressFromBase64 for a data
parse Boolean | Object optional Use JSON.parse for a data
mimeType String optional Mime type (only for XMLHttpRequest)
options.encoding String optional Encoding
options.flag String optional File system flag
parse.reviver function optional A function that transforms the results
Returns:
Type Description
Object Loaded data
Examples
const file = new DKTools.IO.File('data/System.json');
const result = file.load({ sync: true, parse: true });

if (result.status === DKTools.IO.OK) {
    console.log(result.data); // data loaded synchronously
}
const file = new DKTools.IO.File('data/System.json');

file.load({
     sync: false,
     parse: true,
     onSuccess: function(result, file) {
         if (result.status === DKTools.IO.OK) {
             console.log(result.data); // data loaded asynchronously
         }
     }
});

loadAsync (object)Promise.<{status: Number, data: (*|null)}> async inherited

Loads and returns a data Asynchronous version of DKTools.IO.File.prototype.load Promise resolves a loaded data or null Promise resolves an object with 3 properties: status - Result of an operation data - Loaded data error - Error of an operation if the status is not equal to DKTools.IO.OK then data will be null Possible statuses: DKTools.IO.OK DKTools.IO.ERROR_PATH_DOES_NOT_EXIST DKTools.IO.ERROR_DECOMPRESSING_DATA DKTools.IO.ERROR_PARSING_DATA
Name Type Default Description
object Object {} optional Options of an operation
Name Type Description
options String | Object optional Options for FileSystem.readFile
decompress Boolean optional Use LZString.decompressFromBase64 for a data
parse Boolean | Object optional Use JSON.parse for a data
options.encoding String optional Encoding
options.flag String optional File system flag
parse.reviver function optional A function that transforms the results
Returns:
Type Description
Promise.<{status: Number, data: (*|null)}> Loaded data

loadAudio ()WebAudio | null inherited

Loads an audio file and returns a WebAudio
Version:
  • 1.1.4
Returns:
Type Description
WebAudio | null Audio file or null

loadAudioAsync ()Promise.<(WebAudio|null)> async inherited

Loads an audio file and returns a WebAudio Asynchronous version of DKTools.IO.File.prototype.loadAudio Promise resolves a loaded audio file or null
Returns:
Type Description
Promise.<(WebAudio|null)> Loaded audio file or null

loadBitmap (object)Bitmap | null inherited

Loads and returns a bitmap
Name Type Description
object function | Object Function of processing after loading a bitmap or object with parameters
Name Type Description
listener function optional Function of processing after loading a bitmap
Returns:
Type Description
Bitmap | null Loaded bitmap or null
Example
const file = new DKTools.IO.File('img/system/Window.png');
const bitmap = file.loadBitmap();

loadBitmapAsync (object)Promise.<Bitmap> async inherited

Loads and returns a bitmap Asynchronous version of DKTools.IO.File.prototype.loadBitmap Promise resolves a loaded bitmap or null
Name Type Description
object function | Object Function of processing after loading a bitmap or object with parameters
Name Type Description
listener function optional Function of processing after loading a bitmap
Returns:
Type Description
Promise.<Bitmap> Loaded bitmap or null
Example
const file = new DKTools.IO.File('img/system/Window.png');
const bitmap = await file.loadBitmapAsync();

loadJson (object)Object inherited

Loads the JSON data Returns an object with 3 properties: status - Result of an operation data - Loaded data error - Error of an operation if the status is not equal to DKTools.IO.OK then data will be null Possible statuses: DKTools.IO.OK DKTools.IO.EXPECT_CALLBACK DKTools.IO.ERROR_PATH_DOES_NOT_EXIST DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE DKTools.IO.ERROR_OPTIONS_ARE_NOT_AVAILABLE DKTools.IO.ERROR_DECOMPRESSING_DATA DKTools.IO.ERROR_PARSING_DATA
Name Type Description
object Object Options of an operation
Name Type Description
sync Boolean optional Use synchronous version of FileSystem.readFile
options String | Object optional Options for FileSystem.readFile or FileSystem.readFileSync
onSuccess function optional Callback function upon completion of an operation (only for object.sync == false)
onError function optional Callback function upon completion of an operation with error (only for object.sync == false)
decompress Boolean optional Use LZString.decompressFromBase64 for a data
parse Boolean | Object optional Use JSON.parse for a data
options.encoding String optional Encoding
options.flag String optional File system flag
parse.reviver function optional A function that transforms the results
Returns:
Type Description
Object Loaded data
Examples
const file = new DKTools.IO.File('data/System.json');
const result = file.loadJson({ sync: true });

if (result.status === DKTools.IO.OK) {
    console.log(result.data); // data loaded synchronously
}
const file = new DKTools.IO.File('data/System.json');

file.loadJson({
     sync: false,
     onSuccess: function(result, file) {
         if (result.status === DKTools.IO.OK) {
             console.log(result.data); // data loaded asynchronously
         }
     }
});

loadJsonAsync (object)Promise.<{status: Number, data: (*|null), error: (Error|undefined)}> async inherited

Loads the JSON data Asynchronous version of DKTools.IO.File.prototype.loadJson Promise resolves an object with 3 properties: status - Result of an operation data - Loaded data error - Error of an operation if the status is not equal to DKTools.IO.OK then data will be null Possible statuses: DKTools.IO.OK DKTools.IO.ERROR_PATH_DOES_NOT_EXIST DKTools.IO.ERROR_DECOMPRESSING_DATA DKTools.IO.ERROR_PARSING_DATA
Name Type Default Description
object Object {} optional Options of an operation
Name Type Description
options String | Object optional Options for FileSystem.readFile or FileSystem.readFileSync
decompress Boolean optional Use LZString.decompressFromBase64 for a data
parse Boolean | Object optional Use JSON.parse for a data
options.encoding String optional Encoding
options.flag String optional File system flag
parse.reviver function optional A function that transforms the results
Returns:
Type Description
Promise.<{status: Number, data: (*|null), error: (Error|undefined)}> Loaded data
Example
const file = new DKTools.IO.File('data/System.json');
const data = await file.loadJsonAsync();

remove (object)Number inherited

Removes the file Returns a code of the result of an operation Possible results: DKTools.IO.OK DKTools.IO.EXPECT_CALLBACK DKTools.IO.ERROR_NOT_LOCAL_MODE DKTools.IO.ERROR_PATH_DOES_NOT_EXIST
Name Type Default Description
object Object {} optional Options of an operation
Name Type Description
sync Boolean optional Use synchronous version of FileSystem.unlink
onSuccess function optional Callback function upon completion of an operation (only for object.sync == false)
onError function optional Callback function upon completion of an operation with error (only for object.sync == false)
Returns:
Type Description
Number Code of the result of an operation

removeAsync ()Promise.<Number> async inherited

Removes the file Asynchronous version of DKTools.IO.File.prototype.remove Promise resolves a code of the result of an operation Possible results: DKTools.IO.OK DKTools.IO.ERROR_NOT_LOCAL_MODE DKTools.IO.ERROR_PATH_DOES_NOT_EXIST
Returns:
Type Description
Promise.<Number> Code of the result of an operation

rename (newName, object)Number inherited

Renames the entity (file or directory) Returns a code of the result of an operation Possible results: DKTools.IO.OK DKTools.IO.EXPECT_CALLBACK DKTools.IO.ERROR_NOT_LOCAL_MODE DKTools.IO.ERROR_PATH_DOES_NOT_EXIST DKTools.IO.ERROR_OVERWRITING_IS_NOT_AVAILABLE
Name Type Default Description
newName String New name of entity (file or directory) without the extension
object Object {} optional Options of an operation
Name Type Description
sync Boolean optional Use synchronous version of rename
overwrite Boolean optional Overwrite existing entity
onSuccess function optional Callback function upon completion of an operation (only for object.sync == false)
onError function optional Callback function upon completion of an operation with error (only for object.sync == false)
Returns:
Type Description
Number Code of the result of an operation

renameAsync (newName, object)Promise.<Number> async inherited

Renames the entity (file or directory) Asynchronous version of DKTools.IO.Entity.prototype.rename Promise resolves a code of the result of an operation Possible results: DKTools.IO.OK DKTools.IO.ERROR_NOT_LOCAL_MODE DKTools.IO.ERROR_PATH_DOES_NOT_EXIST DKTools.IO.ERROR_OVERWRITING_IS_NOT_AVAILABLE
Name Type Default Description
newName String New name of entity without the extension
object Object {} optional Options of an operation
Name Type Description
overwrite Boolean optional Overwrite existing entity
Returns:
Type Description
Promise.<Number> Code of the result of an operation

save (data, object)Number inherited

Saves the data Returns a code of the result of an operation Possible results: DKTools.IO.OK DKTools.IO.EXPECT_CALLBACK DKTools.IO.ERROR_NOT_LOCAL_MODE DKTools.IO.ERROR_PATH_DOES_NOT_EXIST
Name Type Default Description
data * Data to save
object Object {} optional Options of an operation
Name Type Description
stringify Boolean | Object optional Use JSON.stringify for the data
compress Boolean optional Use LZString.compressToBase64 for the data
createDirectory Boolean | Object optional Create a directory for the file
sync Boolean optional Use synchronous version of FileSystem.writeFile
options String | Object optional Options for FileSystem.writeFile or FileSystem.writeFileSync
onSuccess function optional Callback function upon completion of an operation (only for object.sync == false)
onError function optional Callback function upon completion of an operation with error (only for object.sync == false)
stringify.replacer function | Array optional A function that transforms the results
stringify.space Number | String optional Insert white space into the output JSON string for readability purposes
createDirectory.options Object optional Options for FileSystem.mkdir or FileSystem.mkdirSync
Name Type Description
recursive Boolean optional Parent folders should be created
mode Number | String optional Directory permission
Returns:
Type Description
Number Code of the result of an operation
Examples
const file = new DKTools.IO.File('test.txt');
const status = file.save('Hello world!', { sync: true });

if (status === DKTools.IO.OK) {
    console.log('saved!'); // data saved synchronously
}
const file = new DKTools.IO.File('test.txt');

file.save('Hello world!', {
     sync: false,
     onSuccess: function(status, file) {
         if (status === DKTools.IO.OK) {
             console.log('saved!'); // data saved asynchronously
         }
     }
});

saveAsync (data, object)Promise.<Number> async inherited

Saves the data Asynchronous version of DKTools.IO.File.prototype.save Promise resolves a code of the result of an operation Possible results: DKTools.IO.OK DKTools.IO.ERROR_NOT_LOCAL_MODE DKTools.IO.ERROR_PATH_DOES_NOT_EXIST
Name Type Default Description
data * Data to save
object Object {} optional Options of an operation
Name Type Description
stringify Boolean optional Use JSON.stringify for the data
compress Boolean optional Use LZString.compressToBase64 for the data
createDirectory Boolean optional Create a directory for the file
options String | Object optional Options for FileSystem.writeFile
stringify.replacer function | Array optional A function that transforms the results
stringify.space Number | String optional Insert white space into the output JSON string for readability purposes
Returns:
Type Description
Promise.<Number> Code of the result of an operation

saveJson (data, object)Number inherited

Saves the JSON data Returns a code of the result of an operation Possible results: DKTools.IO.OK DKTools.IO.EXPECT_CALLBACK DKTools.IO.ERROR_NOT_LOCAL_MODE DKTools.IO.ERROR_PATH_DOES_NOT_EXIST
Name Type Default Description
data Array | Object Data to save
object Object {} optional Options of an operation
Name Type Description
stringify Object optional Use JSON.stringify for the data
compress Boolean optional Use LZString.compressToBase64 for the data
createDirectory Boolean optional Create a directory for the file
sync Boolean optional Use synchronous version of FileSystem.writeFile
options String | Object optional Options for FileSystem.writeFile
onSuccess function optional Callback function upon completion of an operation (only for object.sync == false)
onError function optional Callback function upon completion of an operation with error (only for object.sync == false)
stringify.replacer function | Array optional A function that transforms the results
stringify.space Number | String optional Insert white space into the output JSON string for readability purposes
Returns:
Type Description
Number Code of the result of an operation
Examples
const data = { message: 'Hello world' };
const file = new DKTools.IO.File('test.json');
const status = file.saveJson(data, { sync: true });

if (status === DKTools.IO.OK) {
    console.log('saved!'); // data saved synchronously
}
const data = { message: 'Hello world' };
const file = new DKTools.IO.File('test.json');

file.saveJson(data, {
     sync: false,
     onSuccess: function(status, file) {
         if (status === DKTools.IO.OK) {
             console.log('saved!'); // data saved asynchronously
         }
     }
});

saveJsonAsync (data, object)Promise.<Number> async inherited

Saves the JSON data Asynchronous version of DKTools.IO.File.prototype.saveJson Promise resolves a code of the result of an operation Possible results: DKTools.IO.OK DKTools.IO.ERROR_NOT_LOCAL_MODE DKTools.IO.ERROR_PATH_DOES_NOT_EXIST
Name Type Default Description
data Array | Object Data to save
object Object {} optional Options of an operation
Name Type Description
stringify Object optional Use JSON.stringify for the data
compress Boolean optional Use LZString.compressToBase64 for the data
createDirectory Boolean optional Create a directory for the file
options String | Object optional Options for FileSystem.writeFile
stringify.replacer function | Array optional A function that transforms the results
stringify.space Number | String optional Insert white space into the output JSON string for readability purposes
Returns:
Type Description
Promise.<Number> Code of the result of an operation