bn.getFileSystemManager
▸ getFileSystemManager(): FileSystemManager
description
Get the file system manager instance which is a singleton. On Android devices, file system api will save file on external storage by default.- About filePath: filePath should starts from root directory of source code bundle.Only supports absolute path like /a/b
or a/b
.Files with extensions of js,json,bxss,bxm
will be transformed into other files after compilation, so they are not expected to be accessible.
- Valid value of encoding: utf-8, utf8
example
const manager = bn.getFileSystemManager()
manager.readFile({filePath: 'xxx'})
Returns
FileSystemManager
Class: FileSystemManager
Name | Type | Description |
---|---|---|
rpc | RPC | |
readFileNative | undefined | (options : ReadFileOption ) => Promise <FSReadFileResult > | |
writeFileNative | undefined | (options : WriteFileOption ) => Promise <GeneralCallbackResult > | |
readFileNativeSync | undefined | (options : any ) => any | |
writeFileNativeSync | undefined | (options : any ) => any | |
readFile | (options ): Promise <FSReadFileResult > | description Read files in local directory. |
writeFile | (options ): Promise <GeneralCallbackResult > | description Write data into file in local directory. |
mkdir | (options ): Promise <{}> | description Create directory. |
access | (options ): Promise <{}> | description Try to access file/directory. |
unzip | (options ): Promise <{}> | description Unzip file. |
copyFile | (options ): Promise <{}> | description Copy file to another path. |
readFileSync | (filePath , encoding? , position? , length? ): FileData | description Sync version of readFile. |
writeFileSync | (filePath , data , encoding? ): any | description Sync version of writeFile. |
mkdirSync | (dirPath , recursive? ): Object | description Sync version of mkdir. |
accessSync | (path ): Object | description Sync version of access. |
copyFileSync | (srcPath , destPath ): Object | description Sync version of copyFile. |
readFile
▸ readFile(options
): Promise
<FSReadFileResult
>
description
Read files in local directory.
example
bn.getFileSystemManager().readFile({
filePath: `${bn.env.USER_DATA_PATH}/helloWorld.txt`,
encoding: 'utf-8',
success(res) {
console.log(res)
},
})
Parameters
Name | Type |
---|---|
options | ReadFileOption |
Returns
Promise
<FSReadFileResult
>
writeFile
▸ writeFile(options
): Promise
<GeneralCallbackResult
>
description
Write data into file in local directory.
example
bn.getFileSystemManager().writeFile({
filePath: `${bn.env.USER_DATA_PATH}/helloWorld.txt`,
data: 'hello world'
encoding: 'utf-8',
success(res) {
console.log(res)
},
})
Parameters
Name | Type |
---|---|
options | WriteFileOption |
Returns
Promise
<GeneralCallbackResult
>
mkdir
▸ mkdir(options
): Promise
<{}>
description
Create directory.
example
bn.getFileSystemManager().mkdir({
dirPath: 'a/b/c/d',
recursive: true,
success(res) {
console.log(res)
},
})
Parameters
Name | Type |
---|---|
options | FsMkdirOptions |
Returns
Promise
<{}>
access
▸ access(options
): Promise
<{}>
description
Try to access file/directory.
example
bn.getFileSystemManager().access({
path: 'a/b/c/d',
success(res) {
console.log(res)
},
fail(err) {
}
})
Parameters
Name | Type |
---|---|
options | FsAccessOptions |
Returns
Promise
<{}>
unzip
▸ unzip(options
): Promise
<{}>
description
Unzip file.
example
bn.getFileSystemManager().unzip({
zipFilePath: 'foo.zip',
targetPath: 'foo'
success(res) {
console.log(res)
},
})
Parameters
Name | Type |
---|---|
options | FsUnzipOptions |
Returns
Promise
<{}>
copyFile
▸ copyFile(options
): Promise
<{}>
description
Copy file to another path.
example
bn.getFileSystemManager().copyFile({
destPath: 'a/foo',
srcPath: 'a/bar'
success(res) {
console.log(res)
},
})
Parameters
Name | Type |
---|---|
options | FsCopyOptions |
Returns
Promise
<{}>
readFileSync
▸ readFileSync(filePath
, encoding?
, position?
, length?
): FileData
description
Sync version of readFile.
example
bn.getFileSystemManager().readFileSync(`${bn.env.USER_DATA_PATH}/helloWorld.txt`,'utf-8')
})
Parameters
Name | Type |
---|---|
filePath | string |
encoding? | "ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1" |
position? | number |
length? | number |
Returns
FileData
writeFileSync
▸ writeFileSync(filePath
, data
, encoding?
): any
description
Sync version of writeFile.
example
bn.getFileSystemManager()
.writeFileSync(
`${bn.env.USER_DATA_PATH}/helloWorld.txt`,
'hello world',
'utf-8'
)
})
Parameters
Name | Type |
---|---|
filePath | string |
data | FileData |
encoding? | "ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1" |
Returns
any
mkdirSync
▸ mkdirSync(dirPath
, recursive?
): Object
description
Sync version of mkdir.
example
bn.getFileSystemManager()
.writeFileSync(
`${bn.env.USER_DATA_PATH}/helloWorld.txt`,
'hello world',
'utf-8'
)
})
Parameters
Name | Type |
---|---|
dirPath | string |
recursive? | boolean |
Returns
Object
accessSync
▸ accessSync(path
): Object
description
Sync version of access.
example
bn.getFileSystemManager()
.accessSync(
`${bn.env.USER_DATA_PATH}/helloWorld.txt`
)
})