File
Grants access to a persistent file system manager for reading, writing, copying, and managing local files and directories within the mini game sandbox storage.
TTMinis.game.getFileSystemManager()
Gets the globally unique file system manager.
Returns
FileSystemManager - The file system manager instance.
Example
const fs = TTMinis.game.getFileSystemManager();FileSystemManager
FileSystemManager.readFile(opts)
Reads local file content.
Parameters
Field | Type | Description | Required |
|
| The path of the file to read (local path) | Yes |
|
| Specifies the character encoding for reading the file. If | No |
|
| The position to start reading from. If not specified, reading starts from the beginning of the file. The valid range is [0, fileLength - 1]. Unit: byte. | No |
|
| The number of bytes to read. If not specified, reads to the end of the file. Valid range: [1, fileLength]. Unit: byte. | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
The success callback receives a result object with the following fields:
Field | Type | Description |
|
| The file content. Returns |
|
| The error message. Returns |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.readFile({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
encoding: 'utf8',
position: 0,
success(res) {
console.log(res.data)
},
fail(res) {
console.error(res)
}
})FileSystemManager.readFileSync(filePath, encoding, position, length)
Synchronously reads local file content. Accepts the same parameters as readFile but as positional arguments: filePath (string), encoding (string, optional), position (int32, optional), and length (int32, optional).
Returns
string | ArrayBuffer - The file content.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
const res = fs.readFileSync(`${TTMinis.game.env.USER_DATA_PATH}/hello.txt`, 'utf8', 0)
console.log(res)
} catch(e) {
console.error(e)
}FileSystemManager.access(opts)
Checks whether a file or directory exists.
Parameters
Field | Type | Description | Required |
|
| The path of the file or directory to check (local path) | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.access({
path: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
success(res) {
// File exists
console.log(res)
},
fail(res) {
// File does not exist or other error
console.error(res)
}
})FileSystemManager.accessSync(path)
Synchronously checks whether a file or directory exists. Throws an exception if the path does not exist.
Parameters
Field | Type | Description | Required |
|
| The path of the file or directory to check (local path) | Yes |
Example
const fs = TTMinis.game.getFileSystemManager();
try {
fs.accessSync(`${TTMinis.game.env.USER_DATA_PATH}/hello.txt`)
console.log('File exists')
} catch(e) {
console.error(e)
}FileSystemManager.writeFile(opts)
Writes data to a file.
Parameters
Field | Type | Description | Required |
|
| The path of the file to write (local path) | Yes |
|
| The text or binary data to write | Yes |
|
| Specifies the character encoding for writing the file. Default: | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.writeFile({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
data: 'some text or arrayBuffer',
encoding: 'utf8',
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})FileSystemManager.writeFileSync(filePath, data, encoding)
Synchronously writes data to a file. Accepts the same parameters as writeFile but as positional arguments: filePath (string), data (string or ArrayBuffer), and encoding (string, optional).
Example
const fs = TTMinis.game.getFileSystemManager();
try {
const res = fs.writeFileSync(
`${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
'some text or arrayBuffer',
'utf8'
)
console.log(res)
} catch(e) {
console.error(e)
}FileSystemManager.mkdir(opts)
Creates a directory.
Parameters
Field | Type | Description | Required |
|
| The directory path to create (local path) | Yes |
|
| If | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.mkdir({
dirPath: `${TTMinis.game.env.USER_DATA_PATH}/example`,
recursive: false,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})FileSystemManager.mkdirSync(dirPath, recursive)
Synchronously creates a directory. Accepts dirPath (string) and recursive (Boolean, optional) as positional arguments.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
fs.mkdirSync(`${TTMinis.game.env.USER_DATA_PATH}/example`, false)
console.log('directory created')
} catch(e) {
console.error(e)
}FileSystemManager.copyFile(opts)
Copies a file.
Parameters
Field | Type | Description | Required |
|
| The source file path. Supports local paths. | Yes |
|
| The destination file path. Supports local paths. | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.copyFile({
srcPath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
destPath: `${TTMinis.game.env.USER_DATA_PATH}/hello_copy.txt`,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})FileSystemManager.copyFileSync(srcPath, destPath)
Synchronously copies a file. Accepts srcPath (string) and destPath (string) as positional arguments.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
fs.copyFileSync(
`${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
`${TTMinis.game.env.USER_DATA_PATH}/hello_copy.txt`
)
} catch(e) {
console.error(e)
}FileSystemManager.unzip(opts)
Decompresses a file.
Parameters
Field | Type | Description | Required |
|
| The source file path. Supports local paths. Must be a zip archive. | Yes |
|
| The target directory path. Supports local paths. | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
FileSystemManager.open(opts)
Opens a file and returns a file descriptor.
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file path (local path) | Yes |
|
| The file system flag. Default: | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Valid values for flag:
Value | Description |
| Opens the file for appending. Creates the file if it does not exist. |
| Similar to |
| Opens the file for reading and appending. Creates the file if it does not exist. |
| Similar to |
| Opens the file for appending in synchronous mode. Creates the file if it does not exist. |
| Opens the file for reading and appending in synchronous mode. Creates the file if it does not exist. |
| Opens the file for reading. Throws an exception if the file does not exist. |
| Opens the file for reading and writing. Throws an exception if the file does not exist. |
| Opens the file for writing. Creates the file if it does not exist. Truncates the file if it exists. |
| Similar to |
| Opens the file for reading and writing. Creates the file if it does not exist. Truncates the file if it exists. |
| Similar to |
The success callback receives a result object with the following field:
Field | Type | Description |
|
| The file descriptor |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.open({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+',
success(res) {
console.log(res.fd)
},
fail(res) {
console.error(res)
}
})FileSystemManager.openSync(opts)
Synchronously opens a file and returns a file descriptor. Accepts the same parameters as open with filePath (string, required) and flag (string, optional, default r).
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Returns
string - The file descriptor.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
const fd = fs.openSync({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+'
})
console.log(fd)
} catch(e) {
console.error(e)
}FileSystemManager.close(opts)
Closes a file.
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file descriptor to close. Obtained via | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.open({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+',
success(res) {
fs.close({
fd: res.fd,
success(res) {
console.log('file closed')
},
fail(res) {
console.error(res)
}
})
}
})FileSystemManager.closeSync(opts)
Synchronously closes a file. Accepts fd (string, required) as a parameter object.
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
const fd = fs.openSync({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+'
})
fs.closeSync({ fd: fd })
console.log('file closed')
} catch(e) {
console.error(e)
}FileSystemManager.read(opts)
Reads file content using a file descriptor.
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file descriptor. Obtained via | Yes |
|
| The buffer to write data into. Must be an ArrayBuffer instance. | Yes |
|
| The write offset in the buffer. Default: 0. | No |
|
| The number of bytes to read from the file. Default: 0. | No |
|
| The starting position for reading. If not provided or | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
The success callback receives a result object with the following fields:
Field | Type | Description |
|
| The actual number of bytes read |
|
| The buffer object that was written to, which is the |
Example
const fs = TTMinis.game.getFileSystemManager();
const ab = new ArrayBuffer(1024);
fs.open({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+',
success(res) {
fs.read({
fd: res.fd,
arrayBuffer: ab,
length: 10,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})
}
})FileSystemManager.readSync(opts)
Synchronously reads file content using a file descriptor. Accepts the same parameters as read (without success, fail, and complete callbacks).
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Returns
ReadResult object with the following fields:
Field | Type | Description |
|
| The actual number of bytes read |
|
| The buffer object that was written to, which is the |
FileSystemManager.write(opts)
Writes data to a file using a file descriptor.
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file descriptor. Obtained via | Yes |
|
| The content to write. Type is | Yes |
|
| Only effective when | No |
|
| Only effective when | No |
|
| Only effective when | No |
|
| Specifies the offset from the beginning of the file where data is written. If not provided or not a number, data is written at the current file pointer position. | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
The success callback receives a result object with the following field:
Field | Type | Description |
|
| The actual number of bytes written to the file. Note that the number of bytes written may not equal the number of characters in the string. |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.open({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+',
success(res) {
fs.write({
fd: res.fd,
data: 'some text',
success(res) {
console.log(res.bytesWritten)
},
fail(res) {
console.error(res)
}
})
}
})FileSystemManager.writeSync(opts)
Synchronously writes data to a file using a file descriptor. Accepts the same parameters as write (without success, fail, and complete callbacks).
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Returns
WriteResult object with the following field:
Field | Type | Description |
|
| The actual number of bytes written to the file |
Example
const fs = TTMinis.game.getFileSystemManager();
try {
const fd = fs.openSync({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+'
})
const res = fs.writeSync({
fd: fd,
data: 'some text'
})
console.log(res.bytesWritten)
} catch(e) {
console.error(e)
}FileSystemManager.rmdir(opts)
Removes a directory.
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The directory path to remove (local path) | Yes |
|
| If | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.rmdir({
dirPath: `${TTMinis.game.env.USER_DATA_PATH}/example`,
recursive: false,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})FileSystemManager.rmdirSync(dirPath, recursive)
Synchronously removes a directory. Accepts dirPath (string) and recursive (Boolean, optional) as positional arguments.
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
fs.rmdirSync(`${TTMinis.game.env.USER_DATA_PATH}/example`, false)
console.log('directory removed')
} catch(e) {
console.error(e)
}FileSystemManager.readdir(opts)
Reads the file list within a directory.
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The directory path to read (local path) | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
The success callback receives a result object with the following field:
Field | Type | Description |
|
| An array of file names in the specified directory |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.readdir({
dirPath: `${TTMinis.game.env.USER_DATA_PATH}/example`,
success(res) {
console.log(res.files)
},
fail(res) {
console.error(res)
}
})FileSystemManager.readdirSync(dirPath)
Synchronously reads the file list within a directory. Accepts dirPath (string) as a positional argument.
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Returns
list<string> - An array of file names in the specified directory.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
const res = fs.readdirSync(`${TTMinis.game.env.USER_DATA_PATH}/example`)
console.log(res)
} catch(e) {
console.error(e)
}FileSystemManager.unlink(opts)
Deletes a file.
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file path to delete (local path) | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.unlink({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})FileSystemManager.unlinkSync(filePath)
Synchronously deletes a file. Accepts filePath (string) as a positional argument.
Note: Supported starting from SDK version 0.15.0. Lower versions must be adjusted for compatibility.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
fs.unlinkSync(`${TTMinis.game.env.USER_DATA_PATH}/hello.txt`)
console.log('file removed')
} catch(e) {
console.error(e)
}FileSystemManager.stat(opts)
Gets the file Stats object.
Note: Supported starting from SDK version 0.16.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file or directory path (local path) | Yes |
|
| If | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
The success callback receives a result object with the following field:
Field | Type | Description |
|
| When |
Stats object
Field | Type | Description |
|
| The file type and access permissions. Corresponds to POSIX |
|
| The file size in bytes. Corresponds to POSIX |
|
| The last time the file was accessed or executed. UNIX timestamp. Corresponds to POSIX |
|
| The last time the file was modified. UNIX timestamp. Corresponds to POSIX |
Stats object methods:
Method | Return type | Description |
|
| Checks whether the file is a directory |
|
| Checks whether the file is a regular file |
Example
const fs = TTMinis.game.getFileSystemManager();
// recursive is false
fs.stat({
path: `${TTMinis.game.env.USER_DATA_PATH}/testDir`,
success(res) {
console.log(res.stats.isDirectory())
},
fail(res) {
console.error(res)
}
})
// recursive is true
fs.stat({
path: `${TTMinis.game.env.USER_DATA_PATH}/testDir`,
recursive: true,
success(res) {
Object.keys(res.stats).forEach(path => {
let stats = res.stats[path]
console.log(path, stats.isDirectory())
})
},
fail(res) {
console.error(res)
}
})FileSystemManager.statSync(path, recursive)
Synchronously gets the file Stats object. Accepts path (string) and recursive (Boolean, optional) as positional arguments.
Note: Supported starting from SDK version 0.16.0. Lower versions must be adjusted for compatibility.
Returns
Stats | list<FileStats> - When recursive is false, returns a Stats object. When recursive is true and path is a directory, returns an array.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
const stats = fs.statSync(`${TTMinis.game.env.USER_DATA_PATH}/testDir`, false)
console.log(stats.isDirectory())
} catch(e) {
console.error(e)
}FileSystemManager.fstat(opts)
Gets the file status information using a file descriptor.
Note: Supported starting from SDK version 0.16.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file descriptor. Obtained via | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
The success callback receives a result object with the following field:
Field | Type | Description |
|
| The Stats object containing the file status information |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.open({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+',
success(res) {
fs.fstat({
fd: res.fd,
success(res) {
console.log(res.stats)
},
fail(res) {
console.error(res)
}
})
}
})FileSystemManager.fstatSync(opts)
Synchronously gets the file status information using a file descriptor. Accepts a parameter object with fd (string, required).
Note: Supported starting from SDK version 0.16.0. Lower versions must be adjusted for compatibility.
Returns
Stats - The Stats object containing the file status information.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
const fd = fs.openSync({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+'
})
const stats = fs.fstatSync({ fd: fd })
console.log(stats)
} catch(e) {
console.error(e)
}FileSystemManager.rename(opts)
Renames a file. Moves a file from oldPath to newPath.
Note: Supported starting from SDK version 0.16.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The source file path. Supports local paths. | Yes |
|
| The new file path. Supports local paths. | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.rename({
oldPath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
newPath: `${TTMinis.game.env.USER_DATA_PATH}/hello_new.txt`,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})FileSystemManager.renameSync(oldPath, newPath)
Synchronously renames a file. Accepts oldPath (string) and newPath (string) as positional arguments.
Note: Supported starting from SDK version 0.16.0. Lower versions must be adjusted for compatibility.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
fs.renameSync(
`${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
`${TTMinis.game.env.USER_DATA_PATH}/hello_new.txt`
)
console.log('rename success')
} catch(e) {
console.error(e)
}FileSystemManager.getFileInfo(opts)
Gets information about a local temporary file or local cached file.
Note: Supported starting from SDK version 0.16.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file path to read (local path) | Yes |
|
| The algorithm for computing the file digest. Default: | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
The success callback receives a result object with the following fields:
Field | Type | Description |
|
| The file size in bytes |
|
| The file digest computed using the specified |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.getFileInfo({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
digestAlgorithm: 'md5',
success(res) {
console.log(res.size)
console.log(res.digest)
},
fail(res) {
console.error(res)
}
})FileSystemManager.saveFile(opts)
Saves a temporary file to local storage. This interface moves the temporary file, so tempFilePath is no longer available after a successful call.
Note: Supported starting from SDK version 0.16.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The temporary file path (local path) | Yes |
|
| The destination file path (local path) | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
The success callback receives a result object with the following field:
Field | Type | Description |
|
| The saved file path (local path) |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.saveFile({
tempFilePath: '/tmp/tempFile.txt',
filePath: `${TTMinis.game.env.USER_DATA_PATH}/savedFile.txt`,
success(res) {
console.log(res.savedFilePath)
},
fail(res) {
console.error(res)
}
})FileSystemManager.saveFileSync(tempFilePath, filePath)
Synchronously saves a temporary file to local storage. Accepts tempFilePath (string) and filePath (string, optional) as positional arguments.
Note: Supported starting from SDK version 0.16.0. Lower versions must be adjusted for compatibility.
Returns
string - The saved file path (local path).
Example
const fs = TTMinis.game.getFileSystemManager();
try {
const savedFilePath = fs.saveFileSync(
'/tmp/tempFile.txt',
`${TTMinis.game.env.USER_DATA_PATH}/savedFile.txt`
)
console.log(savedFilePath)
} catch(e) {
console.error(e)
}FileSystemManager.getSavedFileList(opts)
Gets the list of saved local cache files.
Note: Supported starting from SDK version 0.16.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
The success callback receives a result object with the following field:
Field | Type | Description |
|
| An array of file objects |
Each item in fileList has the following structure:
Field | Type | Description |
|
| The file path (local path) |
|
| The local file size in bytes |
|
| The timestamp when the file was saved, in seconds since 1970/01/01 08:00:00 |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.getSavedFileList({
success(res) {
console.log(res.fileList)
},
fail(res) {
console.error(res)
}
})FileSystemManager.removeSavedFile(opts)
Removes a saved local cache file.
Note: Supported starting from SDK version 0.16.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file path to remove (local path) | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.removeSavedFile({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/savedFile.txt`,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})FileSystemManager.appendFile(opts)
Appends content to the end of a file.
Note: Supported starting from SDK version 0.18.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file path to append to (local path) | Yes |
|
| The text or binary data to append | Yes |
|
| Specifies the character encoding for writing. Default: | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.appendFile({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
data: 'some text',
encoding: 'utf8',
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})FileSystemManager.appendFileSync(filePath, data, encoding)
Synchronously appends content to the end of a file. Accepts filePath (string), data (string or ArrayBuffer), and encoding (string, optional) as positional arguments.
Note: Supported starting from SDK version 0.18.0. Lower versions must be adjusted for compatibility.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
fs.appendFileSync(
`${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
'some text',
'utf8'
)
console.log('appendFile success')
} catch(e) {
console.error(e)
}FileSystemManager.truncate(opts)
Truncates the content of a file.
Note: Supported starting from SDK version 0.18.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file path to truncate (local path) | Yes |
|
| The truncation position. Default: 0. If | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.truncate({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
length: 10,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})FileSystemManager.truncateSync(opts)
Synchronously truncates the content of a file. Accepts a parameter object with filePath (string, required) and length (int32, optional, default 0).
Note: Supported starting from SDK version 0.18.0. Lower versions must be adjusted for compatibility.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
fs.truncateSync({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
length: 10
})
console.log('truncate success')
} catch(e) {
console.error(e)
}FileSystemManager.ftruncate(opts)
Truncates the content of a file using a file descriptor.
Note: Supported starting from SDK version 0.18.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file descriptor. Obtained via | Yes |
|
| The truncation position. Default: 0. If | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.open({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+',
success(res) {
fs.ftruncate({
fd: res.fd,
length: 10,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})
}
})FileSystemManager.ftruncateSync(opts)
Synchronously truncates the content of a file using a file descriptor. Accepts a parameter object with fd (string, required) and length (int32, required).
Note: Supported starting from SDK version 0.18.0. Lower versions must be adjusted for compatibility.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
const fd = fs.openSync({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+'
})
fs.ftruncateSync({
fd: fd,
length: 10
})
console.log('ftruncate success')
} catch(e) {
console.error(e)
}FileSystemManager.readCompressedFile(opts)
Reads the content of a local file with a specified compression type.
Note: Supported starting from SDK version 0.18.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The file path to read (local user file or code package file) | Yes |
|
| The file compression type. Currently only supports | Yes |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
The success callback receives a result object with the following field:
Field | Type | Description |
|
| The file content |
Example
const fs = TTMinis.game.getFileSystemManager();
fs.readCompressedFile({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.br`,
compressionAlgorithm: 'br',
success(res) {
console.log(res.data)
},
fail(res) {
console.error(res)
}
})FileSystemManager.readCompressedFileSync(opts)
Synchronously reads the content of a local file with a specified compression type. Accepts a parameter object with filePath (string, required) and compressionAlgorithm (string, required).
Note: Supported starting from SDK version 0.18.0. Lower versions must be adjusted for compatibility.
Returns
ArrayBuffer - The file content.
Example
const fs = TTMinis.game.getFileSystemManager();
try {
const data = fs.readCompressedFileSync({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/hello.br`,
compressionAlgorithm: 'br'
})
console.log(data)
} catch(e) {
console.error(e)
}FileSystemManager.readZipEntry(opts)
Reads files within a compressed archive.
Note: Supported starting from SDK version 0.18.0. Lower versions must be adjusted for compatibility.
Parameters
Field | Type | Description | Required |
|
| The path of the compressed archive to read (local path) | Yes |
|
| The list of files to read from the archive. Pass | Yes |
|
| Specifies the character encoding for reading files. Only effective when | No |
|
| The callback function for a successful API call | No |
|
| The callback function for a failed API call | No |
|
| The callback function for the end of the API call (executed for both success and failure) | No |
When entries is an array, each item has the following structure:
Field | Type | Description | Required |
|
| The file path within the archive | Yes |
|
| Specifies the character encoding for reading the file. If not provided, the file content is read as binary in ArrayBuffer format. | No |
|
| The position to start reading from. If not specified, reading starts from the beginning of the file. Valid range: [0, fileLength - 1]. Unit: byte. | No |
|
| The number of bytes to read. If not specified, reads to the end of the file. Valid range: [1, fileLength]. Unit: byte. | No |
The success callback receives a result object with the following field:
Field | Type | Description |
|
| The file reading results. |
Example
const fs = TTMinis.game.getFileSystemManager();
// Read specific files from a zip
fs.readZipEntry({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/example.zip`,
entries: [{
path: 'some_folder/my_file.txt',
encoding: 'utf-8',
position: 0,
length: 10000
}, {
path: 'other_folder/other_file.txt'
}],
success(res) {
console.log(res.entries)
},
fail(res) {
console.error(res)
}
})
// Read all files from a zip
fs.readZipEntry({
filePath: `${TTMinis.game.env.USER_DATA_PATH}/example.zip`,
entries: 'all',
encoding: 'utf-8',
success(res) {
console.log(res.entries)
},
fail(res) {
console.error(res)
}
})Stats
Stats.isDirectory()
Checks whether the current file is a directory.
Returns
Boolean - Whether the current file is a directory.
Stats.isFile()
Checks whether the current file is a regular file.
Returns
Boolean - Whether the current file is a regular file.
ReadResult
The file reading result, returned by the FileSystemManager.readSync interface.
Field | Type | Description |
|
| The actual number of bytes read |
|
| The buffer object that was written to, which is the |
FileStats
Each FileStats object contains path and stats.
Field | Type | Description |
|
| The file or directory path |
|
| The Stats object describing the file status |