File
# saveFile
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
saveFile(Object object)
Save the file locally.
note
saveFile moves the temporary file, so the tempFilePath passed in after a successful call is unavailable.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| tempFilePath | string | Yes | The temporary path to the file that needs to be saved is | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| savedFilePath | number | The stored file path |
Sample Code
# removeSavedFile
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
removeSavedFile(Object object)
Delete the local cache file.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| tempFilePath | string | Yes | The path of the file that needs to be deleted is | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Sample Code
# openDocument
Base Library 1.3.9 is supported, iOS version 2.1.23, android is not yet supported
openDocument(Object object)
The new page opens the document.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | File path, available via downloadFile | |
| fileType | string | No | File Type, which specifies the file type to open the file | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Legal value for object.fileType
| The value | Description |
|---|---|
| doc | doc format |
| docx | docx format |
| xls | xls format |
| xlsx | xlsx format |
| ppt | ppt format |
| pptx | the pptx format |
| pdf format |
Sample Code
# getSavedFileList
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
getSavedFileList(Object object)
Gets a list of saved local cache files in the MiniApp directory.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| fileList | Array.<Object> | array of files, each of which is a FileItem |
Structure of res.fileList
| Properties | Type | Description |
|---|---|---|
| filePath | string | The local path |
| size | number | Local file size, in bytes |
| createTime | number | The timestamp at the time the file was saved, from 01/01/1970 08:00:00 to the current time of |
Sample Code
# getSavedFileInfo
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
getSavedFileInfo(Object object)
Gets the file information for the local file. This interface can only be used to get files that have been saved to the local area, if you need to get temporary file information, use the getFileInfo() interface.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | The file path | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| size | number | Local file size, in B |
| createTime | number | The timestamp at the time the file was saved, from 01/01/1970 08:00:00 to the current time of |
Sample code
# getFileInfo
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
getFileInfo(Object object)
Gets the file information.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | The local file path | |
| digestAlgorithm | string | 'md5' | No | Algorithm for calculating file summaries |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
**object.digestAlgorithm
| The value | Description |
|---|---|
| md5 | The md5 algorithm |
| sha1 | The sha1 algorithm |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| size | number | Local file size, in bytes |
| digest | string | The file summary calculated from the incoming digestAlgorithm |
Sample Code
# getFileSystemManager
Base Library 2.10.6 is supported
getFileSystemManager()
Gets a globally unique filer
Return Value
FileSystemManager
File Manager
# FileSystemManager.access
FileSystemManager.access(Object object)
Determine if a file/directory exists
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| path | string | Yes | The file/directory path (local path) to determine if it exists | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.accessSync
FileSystemManager.accessSync(string path)
[FileSystemManager.access] The synchronized version of (/pages/a49144/).
Parameters
string path
File/directory path to determine if it exists (local path)
Sample code
# FileSystemManager.appendFile
FileSystemManager.appendFile(Object object)
Appends content to the end of the file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | The file path (local path) to append content | |
| data | string/ArrayBuffer | Yes | The text or binary data to append | |
| encoding | string | utf-8 | No | Specifies the character encoding |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
legal value for object.encoding
| The value | Description |
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.appendFileSync
FileSystemManager.appendFileSync(string filePath, string| ArrayBuffer data, string encoding)
Parameters
string filePath
File path (local path) to append content
string| ArrayBuffer data
The text or binary data to append
string encoding
Specifies the character encoding of the file written
Sample code
# FileSystemManager.close
FileSystemManager.close(Object object)
Close the file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| fd | string | Yes | The file descriptor that needs to be closed. fd obtains | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.closeSync
FileSystemManager.closeSync(Object object)
Sync close files
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| fd | string | Yes | The file descriptor that needs to be closed. fd obtains |
Sample code
# FileSystemManager.copyFile
FileSystemManager.copyFile(Object object)
Copy the files
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| srcPath | string | Yes | Source file path, support local path | |
| destPath | string | Yes | Target file path, support local path | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.copyFileSync
FileSystemManager.copyFileSync(string srcPath, string destPath)
Parameters
string srcPath
Source file path, support local path
string destPath
Destination file path, local path supported
Sample code
# FileSystemManager.fstat
FileSystemManager.fstat(Object object)
Gets the status information of the file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| fd | string | Yes | The file descriptor that needs to be closed. fd obtains | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| stats | object | Contains status information for the file |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.fstatSync
FileSystemManager.fstatSync(Object object)
Synchronize to get status information about files
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| fd | string | Yes | The file descriptor that needs to be closed. fd obtains |
Return Value
Object object
An object that contains information about the state of the file
Sample code
# FileSystemManager.ftruncate
FileSystemManager.ftruncate(Object object)
Truncate the contents of the file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| fd | string | Yes | The file descriptor that needs to be closed. fd obtains | |
| length | number | Yes | Truncation position, default 0. If length is less than the file length (in bytes), only the preceding length bytes remain in the file and the rest is deleted; If length is greater than the file length, it is extended, and the extended portion is padded with empty bytes ('\0') | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.ftruncateSync
FileSystemManager.ftruncateSync(Object object)
Synchronization truncates the contents of the file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| fd | string | Yes | The file descriptor that needs to be closed. fd obtains | |
| length | number | Yes | Truncation position, default 0. If length is less than the file length (in bytes), only the preceding length bytes remain in the file and the rest is deleted; If length is greater than the file length, it is extended, and the extended portion is padded with empty bytes ('\0') |
Return Value
undefined
Sample code
# FileSystemManager.getFileInfo
FileSystemManager.getFileInfo(Object object)
Gets the Local Temporary File or Local Cache File information under the MiniApp
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | The file path (local path) to append content | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| size | number | File size, in bytes |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.getSavedFileList
FileSystemManager.getSavedFileList(Object object)
Gets a list of saved local cache files under the MiniApp
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| fileList | Array.<Object> | array of files, and the object contains filePath, size, createTime |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.mkdir
FileSystemManager.mkdir(Object object)
Create a catalog
Parameters
Object object
| Properties | Type | The default value is | Required | illustrate |
|---|---|---|---|---|
| dirPath | string | Yes | Created directory path (local path) | |
| recursive | boolean | false | No | Whether to recursively create the parent directory of the directory before creating the directory. If the corresponding parent directory already exists, the parent directory is not created. If dirPath is a/b/c/d and recursive is true, directory a is created, directory b is created under directory a, and so on until directory d under directory a/b/c is created. |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The interface callback function failed to call | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.mkdirSync
FileSystemManager.mkdirSync(string dirPath, boolean recursive)
Parameters
string dirPath
Created directory path (local path)
boolean recursive
Whether to recursively create the parent directory of the directory before creating the directory. If the corresponding parent directory already exists, the parent directory is not created. If dirPath is a/b/c/d and recursive is true, the a directory is created, the b directory is created under the a directory, and so on until the d directory under the a/b/c directory is created.
Sample code
# FileSystemManager.open
FileSystemManager.open(Object object)
Open the file and return the file descriptor
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | The file path (local path) | |
| flag | string | r | No | File system flag, default: 'r' |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Object.flag legal value
| The value | Description |
|---|---|
| a | Open the file for appending. If the file does not exist, the file is created |
| ax | Similar to 'a', but fails if the path exists |
| a+ | Opens the file for reading and appending. If the file does not exist, the file is created |
| ax+ | Similar to 'a+', but fails if the path exists |
| as | Open the file for appending (in sync mode). If the file does not exist, the file is created |
| as+ | Open files for reading and appending (in synchronous mode). If the file does not exist, the file is created |
| r | Open the file for reading. If the file does not exist, an exception |
| r+ | Opens the file for reading and writing. If the file does not exist, an exception |
| w | Open the file for writing. Creates a file if it does not exist, and truncates the file |
| wx | Similar to 'w', but fails if the path exists |
| w+ | Opens the file for reading and writing. Creates a file if it does not exist, and truncates the file |
| wx+ | Similar to 'w+', but fails if the path exists |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| fd | string | File descriptor |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.openSync
FileSystemManager.openSync(Object object)
Open the file synchronously, returning the file descriptor
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | The file path (local path) | |
| flag | string | r | No | File system flag, default: 'r' |
Object.flag legal value
| The value | Description |
|---|---|
| a | Open the file for appending. If the file does not exist, the file is created |
| ax | Similar to 'a', but fails if the path exists |
| a+ | Opens the file for reading and appending. If the file does not exist, the file is created |
| ax+ | Similar to 'a+', but fails if the path exists |
| as | Open the file for appending (in sync mode). If the file does not exist, the file is created |
| as+ | Open files for reading and appending (in synchronous mode). If the file does not exist, the file is created |
| r | Open the file for reading. If the file does not exist, an exception |
| r+ | Opens the file for reading and writing. If the file does not exist, an exception |
| w | Open the file for writing. Creates a file if it does not exist, and truncates the file |
| wx | Similar to 'w', but fails if the path exists |
| w+ | Opens the file for reading and writing. Creates a file if it does not exist, and truncates the file |
| wx+ | Similar to 'w+', but fails if the path exists |
Return Value
string
File descriptor
Sample code
# FileSystemManager.read
FileSystemManager.read(Object object)
Read the file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| fd | string | Yes | File descriptor. fd obtains | |
| arrayBuffer | ArrayBuffer | Yes | The buffer to which the data is written must be an ArrayBuffer instance | |
| offset | number | 0 | No | The write offset in the buffer, 0 by default |
| length | number | 0 | No | The number of bytes to read from the file, the default is 0 |
| position | number | No | The starting position of the file read, if not passed or null, is read from the position of the current file pointer. If position is a positive integer, the file pointer position remains the same and the file is read from position. | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| bytesRead | number | The actual number of bytes read is |
| arrayBuffer | ArrayBuffer | The object of the cache that is written, that is, the arrayBuffer |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.readdir
FileSystemManager.readdir(Object object)
Reads a list of files in the directory
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| dirPath | string | Yes | The directory path (local path) to read | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| files | Array.<string> | specifies the file name array |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.readdirSync
FileSystemManager.readdirSync(string dirPath)
Parameters
string dirPath
Directory path to read (local path)
Return Value
Array.<string> files
An array of file names in the specified directory
Sample code
# FileSystemManager.readFile
FileSystemManager.readFile(Object object)
Reads the contents of a local file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | The path (local path) of the file to read | |
| encoding | string | utf-8 | No | Specifies the character encoding of the read file, or the binary contents of the file are read in ArrayBuffer format if encoding is not passed |
| position | number | No | Reads begin at the location specified in the file, or read from the file header if not. The range of reading should be the left-closed-right-open interval [position, position+length). Valid range: [0, fileLength - 1]. Unit: byte | |
| length | number | No | Specifies the length of the file, or reads to the end of the file if not. Valid range: [1, fileLength]. Unit: byte | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
legal value for object.encoding
| The value | Description |
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| data | string/ArrayBuffer | File Contents |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.readFileSync
FileSystemManager.readFileSync(string filePath, string encoding, number position, number length)
Parameters
string filePath
Path of the file to be read (local path)
string encoding
Specifies the character encoding of the read file, or the binary contents of the file are read in ArrayBuffer format if encoding is not passed
Legal value for encoding
| The value | Description |
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 |
number position
Reads begin at the location specified in the file, or read from the file header if not. The range of reading should be the left-closed-right-open interval [position, position+length). Valid range: [0, fileLength - 1]. Unit: byte
number length
Specifies the length of the file, or reads to the end of the file if not. Valid range: [1, fileLength]. Unit: byte
Return Value
string| ArrayBuffer data
File contents
Sample code
# FileSystemManager.readSync
FileSystemManager.readSync(Object object)
Read the file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| fd | string | Yes | File descriptor. fd obtains | |
| arrayBuffer | ArrayBuffer | Yes | The buffer to which the data is written must be an ArrayBuffer instance | |
| offset | number | 0 | No | The write offset in the buffer, 0 by default |
| length | number | 0 | No | The number of bytes to read from the file, the default is 0 |
| position | number | No | The starting position of the file read, if not passed or null, is read from the position of the current file pointer. If position is a positive integer, the file pointer position remains the same and the file is read from position. |
Return Value
Object res
| Properties | Type | Description |
|---|---|---|
| bytesRead | number | The actual number of bytes read is |
| arrayBuffer | ArrayBuffer | The object of the cache that is written, that is, the arrayBuffer |
Sample code
# FileSystemManager.removeSavedFile
FileSystemManager.removeSavedFile(Object object)
Delete the local cache files that have been saved under the MiniApp
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | The file path (local path) that needs to be deleted | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.rename
FileSystemManager.rename(Object object)
Rename the file. You can move files from oldPath to newPath
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| oldPath | string | Yes | Source file path, support local path | |
| newPath | string | Yes | New file path, supporting local path | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.renameSync
FileSystemManager.renameSync(string oldPath, string newPath)
Parameters
string oldPath
Source file path, support local path
string newPath
New file path, support local path
Sample code
# FileSystemManager.rmdir
FileSystemManager.rmdir(Object object)
Delete the directory
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| dirPath | string | Yes | The directory path (local path) to delete | |
| recursive | boolean | false | No | Whether to recursively delete the directory. If true, deletes the directory and all subdirectories under the directory, as well as the file |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.rmdirSync
FileSystemManager.rmdirSync(string dirPath, boolean recursive)
Parameters
string dirPath
Directory path to delete (local path)
boolean recursive
Whether to recursively delete the directory. If true, deletes the directory and all subdirectories and files under that directory
Sample code
# FileSystemManager.saveFile
FileSystemManager.saveFile(Object object)
Save the temporary file locally. This interface moves temporary files, so tempFilePath is unavailable after a successful call.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| tempFilePath | string | Yes | Temporarily store file paths (local paths) | |
| filePath | string | No | The file path to store (local path) | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| savedFilePath | string | The stored file path (local path) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.saveFileSync
FileSystemManager.saveFileSync(string tempFilePath, string filePath)
Parameters
string tempFilePath
Temporary storage file path (local path)
string filePath
File path to store (local path)
Sample code
# FileSystemManager.stat
FileSystemManager.stat(Object object)
Gets the file information object
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| path | string | Yes | File/directory path (local path) | |
| recursive | boolean | false | No | Whether to recursively get information about each file under the directory |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| stats | object/Array.<object> | when recursive is false, res.stats is an object. When recursive is true and path is the path to a directory, res.stats is an Array, and each item of the array is an object, and each object contains path and stats. |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.statSync
FileSystemManager.statSync(string path, boolean recursive)
Parameters
string path
File/Directory Path (Local Path)
string recursive
Whether to recursively get stats information for each file under the directory
Return Value
object| Array.<object>
When recursive is false, res.stats is an object. When recursive is true and path is the path to a directory, res.stats is an Array, and each item of the array is an object, and each object contains path and stats.
Sample code
# FileSystemManager.truncate
FileSystemManager.truncate(Object object)
Truncate the contents of the file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | The file path (local path) to truncate | |
| length | number | 0 | Yes | Truncation position, default 0. If length is less than the file length (bytes), only the preceding length bytes remain in the file and the rest is deleted; If length is greater than the file length, it is extended, and the extended portion is padded with empty bytes ('\0') |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.truncateSync
FileSystemManager.truncateSync(Object object)
Parameters
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | The file path (local path) to truncate | |
| length | number | 0 | Yes | Truncation position, default 0. If length is less than the file length (bytes), only the preceding length bytes remain in the file and the rest is deleted; If length is greater than the file length, it is extended, and the extended portion is padded with empty bytes ('\0') |
Sample code
# FileSystemManager.unlink
FileSystemManager.unlink(Object object)
Delete the file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | The file path (local path) to delete | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.unlinkSync
FileSystemManager.unlinkSync(string filePath)
Parameters
string filePath
File path to delete (local path)
Sample code
# FileSystemManager.unzip
FileSystemManager.unzip(Object object)
Unzip the file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| zipFilePath | string | Yes | Source file path, support local paths, can only be zip compressed files | |
| targetPath | string/ArrayBuffer | Yes | Target directory path, support local path | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.write
FileSystemManager.write(Object object)
Write to a file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| fd | string | Yes | File descriptor. fd obtains | |
| data | string/ArrayBuffer | Yes | Writes, of type String or ArrayBuffer | |
| offset | number | 0 | No | Valid only if the data type is ArrayBuffer, which determines which part of the arrayBuffer to be written to, that is, the index in arrayBuffer, with a default of 0 |
| length | number | No | Valid only if the data type is ArrayBuffer, specifying the number of bytes to write, defaulting to the number of bytes remaining after arrayBuffer offsets offset from 0 to | |
| encoding | string | utf-8 | No | Valid only if the data type is String, specifies the character encoding of the file written to, which defaults to UTF8 |
| position | number | No | Specifies the offset at the beginning of the file, which is where the data is to be written. When position is not passed or a value of type other than Number is passed in, the data is written to the location of the current pointer. | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
legal value for object.encoding
| The value | Description |
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| bytesWritten | number | The number of bytes actually written to the file (note that the number of bytes written is not necessarily the same as the number of string characters being written) |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.writeFile
FileSystemManager.writeFile(Object object)
Write to a file
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| filePath | string | Yes | The file path to write to (local path) | |
| data | string/ArrayBuffer | Yes | The text or binary data to write | |
| encoding | string | utf-8 | No | Specifies the character encoding |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
legal value for object.encoding
| The value | Description |
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| errMsg | string | Error message |
Sample code
# FileSystemManager.writeFileSync
FileSystemManager.writeFileSync(string filePath, string| ArrayBuffer data, string encoding)
Parameters
string filePath
File path to write (local path)
string| ArrayBuffer data
The text or binary data to write
string encoding
Specifies the character encoding of the file written
legal value for object.encoding
| The value | Description |
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 |
Sample code
# FileSystemManager.writeSync
FileSystemManager.writeSync(Object object)
Write files synchronously
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| fd | string | Yes | File descriptor. fd obtains | |
| data | string/ArrayBuffer | Yes | Writes, of type String or ArrayBuffer | |
| offset | number | 0 | No | Valid only if the data type is ArrayBuffer, which determines which part of the arrayBuffer to be written to, that is, the index in arrayBuffer, with a default of 0 |
| length | number | No | Valid only if the data type is ArrayBuffer, specifying the number of bytes to write, defaulting to the number of bytes remaining after arrayBuffer offsets offset from 0 to | |
| encoding | string | utf-8 | No | Valid only if the data type is String, specifies the character encoding of the file written to, which defaults to UTF8 |
| position | number | No | Specifies the offset at the beginning of the file, which is where the data is to be written. When position is not passed or a value of type other than Number is passed in, the data is written to the location of the current pointer. |
legal value for object.encoding
| The value | Description |
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 |
Return Value
Object res
| Properties | Type | Description |
|---|---|---|
| bytesWritten | number | The number of bytes actually written to the file (note that the number of bytes written is not necessarily the same as the number of string characters being written) |
Sample code