-
__processError
(error, onError)
private
inherited
-
Name |
Type |
Description |
error |
*
|
Error |
onError |
function
|
optional
Callback function upon completion of an operation with error |
- Since:
-
_detectExtension
()
private
-
Detects the extension
- Version:
- Since:
-
copy
(destination, object)Number
-
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 |
|
|
- Since:
Returns:
Type |
Description |
Number
|
Code of the result of an operation |
-
copyAsync
(destination, object)Promise.<Number>
async
-
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 |
|
|
- Since:
Returns:
Type |
Description |
Promise.<Number>
|
Code of the result of an operation |
-
-
Returns true is the entity is same
- Since:
Returns:
Type |
Description |
Boolean
|
Entity is same |
-
-
Returns true if the entity exists
- Version:
Returns:
Type |
Description |
Boolean
|
Entity exists |
-
-
Returns the absolute path
- Since:
Returns:
Type |
Description |
String
|
Absolute path |
-
-
Returns the directory of the file
Returns:
-
getDirectoryName
()String
-
Returns the directory name
- Since:
Returns:
Type |
Description |
String
|
Directory name |
-
-
Returns the extension of the file
- Version:
- Since:
Returns:
Type |
Description |
String
|
Extension of the file |
-
-
Returns the full name
- Version:
- Since:
Returns:
Type |
Description |
String
|
Full name |
-
-
Returns the full path
- Version:
Returns:
Type |
Description |
String
|
Full Path |
-
-
Returns the name of the entity without an extension
- Since:
Returns:
Type |
Description |
String
|
Name of the entity without an extension |
-
-
Returns the path
- Since:
Returns:
Type |
Description |
String
|
Path |
-
-
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) |
|
- Version:
- Since:
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
- Version:
- Since:
Returns:
Type |
Description |
Promise.<Object>
|
Loaded stats |
-
-
Returns true if the entity has an extension
- Since:
Returns:
Type |
Description |
Boolean
|
Entity has an extension |
-
-
Initializes the file
Name |
Type |
Description |
fullPath |
String
|
Path to file |
- Version:
- Since:
-
-
Returns true if an extension of the file is equal to .ogg or .m4a or .rpgmvo
- Version:
Returns:
Type |
Description |
Boolean
|
Extension of the file is equal to .ogg or .m4a or .rpgmvo |
-
-
Returns true if the entity is a directory
- Version:
- Since:
Returns:
Type |
Description |
Boolean
|
Entity is a directory |
-
-
Returns true if the entity is a file
- Version:
- Since:
Returns:
Type |
Description |
Boolean
|
Entity is a file |
-
-
Returns true if an extension of the file is equal to .png, .rpgmvp or .webp
- Version:
Returns:
Type |
Description |
Boolean
|
Extension of the file is equal to .png, .rpgmvp or .webp |
-
-
Returns true if an extension of the file is equal to .json
Returns:
Type |
Description |
Boolean
|
Extension of the file is equal to .json |
-
-
Returns true if an extension of the file is equal to .rpgsave
Returns:
Type |
Description |
Boolean
|
Extension of the file is equal to .rpgsave |
-
-
Returns true if an extension of the file is equal to .dds
- Since:
Returns:
Type |
Description |
Boolean
|
Extension of the file is equal to .dds |
-
-
Returns true if an extension of the file is equal to .txt
- Since:
Returns:
Type |
Description |
Boolean
|
Extension of the file is equal to .txt |
-
-
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 |
-
-
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 |
|
- Version:
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
-
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 |
|
- Version:
- Since:
Returns:
Type |
Description |
Promise.<{status: Number, data: (*|null)}>
|
Loaded data |
-
loadAudio
()WebAudio | null
-
Loads an audio file and returns a WebAudio
- Version:
- Since:
Returns:
Type |
Description |
WebAudio
|
null
|
Audio file or null |
-
loadAudioAsync
()Promise.<(WebAudio|null)>
async
-
Loads an audio file and returns a WebAudio
Asynchronous version of DKTools.IO.File.prototype.loadAudio
Promise resolves a loaded audio file or null
- Since:
Returns:
Type |
Description |
Promise.<(WebAudio|null)>
|
Loaded audio file or null |
-
loadBitmap
(object, hue, smooth)Bitmap | null
-
Loads and returns a bitmap
Name |
Type |
Description |
object |
function
|
Object
|
Function of processing after loading a bitmap or object with parameters |
hue |
Number
|
optional
Hue of bitmap (if object is String) |
smooth |
Boolean
|
optional
Smooth of bitmap (if object is String) |
object.listener |
function
|
optional
Function of processing after loading a bitmap |
object.hue |
Number
|
optional
Hue of bitmap |
object.smooth |
Boolean
|
optional
Smooth of bitmap |
- Version:
- Since:
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, hue, smooth)Promise.<Bitmap>
async
-
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 |
hue |
Number
|
optional
Hue of bitmap (if object is String) |
smooth |
Boolean
|
optional
Smooth of bitmap (if object is String) |
object.listener |
function
|
optional
Function of processing after loading a bitmap |
object.hue |
Number
|
optional
Hue of bitmap |
object.smooth |
Boolean
|
optional
Smooth of bitmap |
- Version:
- Since:
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();
-
-
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 |
|
- Version:
- Since:
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
-
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 |
|
- Version:
- Since:
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();
-
-
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) |
|
- Version:
Returns:
Type |
Description |
Number
|
Code of the result of an operation |
-
removeAsync
()Promise.<Number>
async
-
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
- Version:
- Since:
Returns:
Type |
Description |
Promise.<Number>
|
Code of the result of an operation |
-
-
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) |
|
- Version:
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 |
|
- Version:
- Since:
Returns:
Type |
Description |
Promise.<Number>
|
Code of the result of an operation |
-
reserveBitmap
(object, hue, smooth, reservationId)Bitmap | null
-
Loads, reserves and returns a bitmap
Name |
Type |
Description |
object |
function
|
Object
|
Function of processing after loading a bitmap or object with parameters |
hue |
Number
|
optional
Hue of bitmap (if object is String) |
smooth |
Boolean
|
optional
Smooth of bitmap (if object is String) |
reservationId |
Number
|
optional
Reservation ID (if object is String) |
object.listener |
function
|
optional
Function of processing after loading a bitmap |
object.hue |
Number
|
optional
Hue of bitmap |
object.smooth |
Boolean
|
optional
Smooth of bitmap |
object.reservationId |
Number
|
optional
Reservation ID |
- Since:
Returns:
Type |
Description |
Bitmap
|
null
|
Loaded bitmap or null |
-
reserveBitmapAsync
(object, hue, smooth, reservationId)Promise.<(Bitmap|null)>
async
-
Loads, reserves and returns a bitmap
Asynchronous version of DKTools.IO.File.prototype.reserveBitmap
Promise resolves a loaded bitmap or null
Name |
Type |
Description |
object |
function
|
Object
|
Function of processing after loading a bitmap or object with parameters |
hue |
Number
|
optional
Hue of bitmap (if object is String) |
smooth |
Boolean
|
optional
Smooth of bitmap (if object is String) |
reservationId |
Number
|
optional
Reservation ID (if object is String) |
object.listener |
function
|
optional
Function of processing after loading a bitmap |
object.hue |
Number
|
optional
Hue of bitmap |
object.smooth |
Boolean
|
optional
Smooth of bitmap |
object.reservationId |
Number
|
optional
Reservation ID |
- Since:
Returns:
Type |
Description |
Promise.<(Bitmap|null)>
|
Loaded bitmap or null |
-
save
(data, object)Number
-
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 |
|
|
- Version:
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
-
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 |
|
- Version:
- Since:
Returns:
Type |
Description |
Promise.<Number>
|
Code of the result of an operation |
-
saveJson
(data, object)Number
-
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 |
|
- Since:
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
-
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 |
|
- Since:
Returns:
Type |
Description |
Promise.<Number>
|
Code of the result of an operation |