Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
错误信息可选值:- 'fail no such file or directory ${path}': 文件/目录不存在;
AppendFileOption
参数
类型
必填
说明
data
string or ArrayBuffer
是
要追加的文本或二进制数据
filePath
string
是
要追加内容的文件路径
complete
(res: CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
encoding
"ascii" or "base64" or "binary" or "hex" or "ucs2" or "ucs-2" or "utf16le" or "utf-16le" or "utf-8" or "utf8" or "latin1"
否
指定写入文件的字符编码
fail
(result: AppendFileFailCallbackResult) => void
否
接口调用失败的回调函数
success
(res: CallbackResult) => void
否
接口调用成功的回调函数
AppendFileFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail no such file or directory, open ${filePath}': 指定的 filePath 文件不存在;- 'fail illegal operation on a directory, open "${filePath}"': 指定的 filePath 是一个已经存在的目录;- 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有写权限;- 'fail sdcard not mounted': 指定的 filePath 是一个已经存在的目录;
CopyFileOption
参数
类型
必填
说明
destPath
string
是
目标文件路径
srcPath
string
是
源文件路径,只可以是普通文件
complete
(res: CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: CopyFileFailCallbackResult) => void
否
接口调用失败的回调函数
success
(res: CallbackResult) => void
否
接口调用成功的回调函数
CopyFileFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail permission denied, copyFile ${srcPath} -> ${destPath}': 指定目标文件路径没有写权限;- 'fail no such file or directory, copyFile ${srcPath} -> ${destPath}': 源文件不存在,或目标文件路径的上层目录不存在;- 'fail the maximum size of the file storage limit is exceeded': 存储空间不足;
错误信息可选值:- 'fail no such file or directory, open ${filePath}': 指定的 filePath 所在目录不存在;- 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有读权限;
ReaddirOption
参数
类型
必填
说明
dirPath
string
是
要读取的目录路径
complete
(res: CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: ReaddirFailCallbackResult) => void
否
接口调用失败的回调函数
success
(result: ReaddirSuccessCallbackResult) => void
否
接口调用成功的回调函数
ReaddirFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail no such file or directory ${dirPath}': 目录不存在;- 'fail not a directory ${dirPath}': dirPath 不是目录;- 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有读权限;
错误信息可选值:- 'fail file not exist': 指定的 tempFilePath 找不到文件;
RenameOption
参数
类型
必填
说明
newPath
string
是
新文件路径
oldPath
string
是
源文件路径,可以是普通文件或目录
complete
(res: CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: RenameFailCallbackResult) => void
否
接口调用失败的回调函数
success
(res: CallbackResult) => void
否
接口调用成功的回调函数
RenameFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail permission denied, rename ${oldPath} -> ${newPath}': 指定源文件或目标文件没有写权限;- 'fail no such file or directory, rename ${oldPath} -> ${newPath}': 源文件不存在,或目标文件路径的上层目录不存在;
RmdirOption
参数
类型
必填
说明
dirPath
string
是
要删除的目录路径
complete
(res: CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: RmdirFailCallbackResult) => void
否
接口调用失败的回调函数
recursive
boolean
否
是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。
success
(res: CallbackResult) => void
否
接口调用成功的回调函数
RmdirFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail no such file or directory ${dirPath}': 目录不存在;- 'fail directory not empty': 目录不为空;- 'fail permission denied, open ${dirPath}': 指定的 dirPath 路径没有写权限;
SaveFileOption
参数
类型
必填
说明
tempFilePath
string
是
临时存储文件路径
complete
(res: CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: SaveFileFailCallbackResult) => void
否
接口调用失败的回调函数
filePath
string
否
要存储的文件路径
success
(result: SaveFileSuccessCallbackResult) => void
否
接口调用成功的回调函数
SaveFileFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail tempFilePath file not exist': 指定的 tempFilePath 找不到文件;- 'fail permission denied, open "${filePath}"': 指定的 filePath 路径没有写权限;- 'fail no such file or directory "${dirPath}"': 上级目录不存在;- 'fail the maximum size of the file storage limit is exceeded': 存储空间不足;
SaveFileSuccessCallbackResult
参数
类型
说明
savedFilePath
number
存储后的文件路径
errMsg
string
调用结果
StatOption
参数
类型
必填
说明
path
string
是
文件/目录路径
complete
(res: CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: StatFailCallbackResult) => void
否
接口调用失败的回调函数
recursive
boolean
否
是否递归获取目录下的每个文件的 Stats 信息
success
(result: StatSuccessCallbackResult) => void
否
接口调用成功的回调函数
StatFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail permission denied, open ${path}': 指定的 path 路径没有读权限;- 'fail no such file or directory ${path}': 文件不存在;
错误信息可选值:- 'fail permission denied, open ${path}': 指定的 path 路径没有读权限;- 'fail no such file or directory ${path}': 文件不存在;- 'fail operation not permitted, unlink ${filePath}': 传入的 filePath 是一个目录;
UnzipOption
参数
类型
必填
说明
targetPath
string
是
目标目录路径
zipFilePath
string
是
源文件路径,只可以是 zip 压缩文件
complete
(res: CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: UnzipFailCallbackResult) => void
否
接口调用失败的回调函数
success
(res: CallbackResult) => void
否
接口调用成功的回调函数
UnzipFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail permission denied, unzip ${zipFilePath} -> ${destPath}': 指定目标文件路径没有写权限;- 'fail no such file or directory, unzip ${zipFilePath} -> "${destPath}': 源文件不存在,或目标文件路径的上层目录不存在;
WriteFileOption
参数
类型
必填
说明
data
string or ArrayBuffer
是
要写入的文本或二进制数据
filePath
string
是
要写入的文件路径
complete
(res: CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
encoding
"ascii" or "base64" or "binary" or "hex" or "ucs2" or "ucs-2" or "utf16le" or "utf-16le" or "utf-8" or "utf8" or "latin1"
否
指定写入文件的字符编码
fail
(result: WriteFileFailCallbackResult) => void
否
接口调用失败的回调函数
success
(res: CallbackResult) => void
否
接口调用成功的回调函数
WriteFileFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail no such file or directory, open ${filePath}': 指定的 filePath 所在目录不存在;- 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有写权限;- 'fail the maximum size of the file storage limit is exceeded': 存储空间不足;
错误信息可选值:- 'fail no such file or directory ${path}': 文件/目录不存在;
AppendFileOption
参数
类型
必填
说明
data
string or ArrayBuffer
是
要追加的文本或二进制数据
filePath
string
是
要追加内容的文件路径
encoding
keyof Encoding
否
指定写入文件的字符编码
complete
(res: TaroGeneral.CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: AppendFileFailCallbackResult) => void
否
接口调用失败的回调函数
success
(res: TaroGeneral.CallbackResult) => void
否
接口调用成功的回调函数
AppendFileFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail no such file or directory, open ${filePath}': 指定的 filePath 文件不存在;- 'fail illegal operation on a directory, open "${filePath}"': 指定的 filePath 是一个已经存在的目录;- 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有写权限;- 'fail sdcard not mounted': 指定的 filePath 是一个已经存在的目录;
CopyFileOption
参数
类型
必填
说明
destPath
string
是
目标文件路径
srcPath
string
是
源文件路径,只可以是普通文件
complete
(res: TaroGeneral.CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: CopyFileFailCallbackResult) => void
否
接口调用失败的回调函数
success
(res: TaroGeneral.CallbackResult) => void
否
接口调用成功的回调函数
CopyFileFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail permission denied, copyFile ${srcPath} -> ${destPath}': 指定目标文件路径没有写权限;- 'fail no such file or directory, copyFile ${srcPath} -> ${destPath}': 源文件不存在,或目标文件路径的上层目录不存在;- 'fail the maximum size of the file storage limit is exceeded': 存储空间不足;
错误信息可选值:- 'fail no such file or directory, open ${filePath}': 指定的 filePath 所在目录不存在;- 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有读权限;
ReaddirOption
参数
类型
必填
说明
dirPath
string
是
要读取的目录路径
complete
(res: TaroGeneral.CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: ReaddirFailCallbackResult) => void
否
接口调用失败的回调函数
success
(result: ReaddirSuccessCallbackResult) => void
否
接口调用成功的回调函数
ReaddirFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail no such file or directory ${dirPath}': 目录不存在;- 'fail not a directory ${dirPath}': dirPath 不是目录;- 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有读权限;
错误信息可选值:- 'fail no such file or directory, open ${filePath}': 指定的 filePath 所在目录不存在- 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有读权限- 'fail sdcard not mounted': Android sdcard 挂载失败
错误信息可选值:- 'fail file not exist': 指定的 tempFilePath 找不到文件;
RenameOption
参数
类型
必填
说明
newPath
string
是
新文件路径
oldPath
string
是
源文件路径,可以是普通文件或目录
complete
(res: TaroGeneral.CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: RenameFailCallbackResult) => void
否
接口调用失败的回调函数
success
(res: TaroGeneral.CallbackResult) => void
否
接口调用成功的回调函数
RenameFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail permission denied, rename ${oldPath} -> ${newPath}': 指定源文件或目标文件没有写权限;- 'fail no such file or directory, rename ${oldPath} -> ${newPath}': 源文件不存在,或目标文件路径的上层目录不存在;
RmdirOption
参数
类型
必填
说明
dirPath
string
是
要删除的目录路径
complete
(res: TaroGeneral.CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: RmdirFailCallbackResult) => void
否
接口调用失败的回调函数
recursive
boolean
否
是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。
success
(res: TaroGeneral.CallbackResult) => void
否
接口调用成功的回调函数
RmdirFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail no such file or directory ${dirPath}': 目录不存在;- 'fail directory not empty': 目录不为空;- 'fail permission denied, open ${dirPath}': 指定的 dirPath 路径没有写权限;
SaveFileOption
参数
类型
必填
说明
tempFilePath
string
是
临时存储文件路径
complete
(res: TaroGeneral.CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: SaveFileFailCallbackResult) => void
否
接口调用失败的回调函数
filePath
string
否
要存储的文件路径
success
(result: SaveFileSuccessCallbackResult) => void
否
接口调用成功的回调函数
SaveFileFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail tempFilePath file not exist': 指定的 tempFilePath 找不到文件;- 'fail permission denied, open "${filePath}"': 指定的 filePath 路径没有写权限;- 'fail no such file or directory "${dirPath}"': 上级目录不存在;- 'fail the maximum size of the file storage limit is exceeded': 存储空间不足;
SaveFileSuccessCallbackResult
参数
类型
说明
savedFilePath
string
存储后的文件路径
errMsg
string
调用结果
StatOption
参数
类型
必填
说明
path
string
是
文件/目录路径
complete
(res: TaroGeneral.CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: StatFailCallbackResult) => void
否
接口调用失败的回调函数
recursive
boolean
否
是否递归获取目录下的每个文件的 Stats 信息
success
(result: StatSuccessCallbackResult) => void
否
接口调用成功的回调函数
StatFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail permission denied, open ${path}': 指定的 path 路径没有读权限;- 'fail no such file or directory ${path}': 文件不存在;
错误信息可选值:- 'fail permission denied, open ${path}': 指定的 path 路径没有读权限;- 'fail no such file or directory ${path}': 文件不存在;- 'fail operation not permitted, unlink ${filePath}': 传入的 filePath 是一个目录;
UnzipOption
参数
类型
必填
说明
targetPath
string
是
目标目录路径
zipFilePath
string
是
源文件路径,只可以是 zip 压缩文件
complete
(res: TaroGeneral.CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: UnzipFailCallbackResult) => void
否
接口调用失败的回调函数
success
(res: TaroGeneral.CallbackResult) => void
否
接口调用成功的回调函数
UnzipFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail permission denied, unzip ${zipFilePath} -> ${destPath}': 指定目标文件路径没有写权限;- 'fail no such file or directory, unzip ${zipFilePath} -> "${destPath}': 源文件不存在,或目标文件路径的上层目录不存在;
WriteFileOption
参数
类型
必填
说明
data
string or ArrayBuffer
是
要写入的文本或二进制数据
filePath
string
是
要写入的文件路径
complete
(res: TaroGeneral.CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
encoding
keyof Encoding
否
指定写入文件的字符编码
fail
(result: WriteFileFailCallbackResult) => void
否
接口调用失败的回调函数
success
(res: TaroGeneral.CallbackResult) => void
否
接口调用成功的回调函数
WriteFileFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail no such file or directory, open ${filePath}': 指定的 filePath 所在目录不存在;- 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有写权限;- 'fail the maximum size of the file storage limit is exceeded': 存储空间不足;
错误信息可选值:- 'bad file descriptor': 无效的文件描述符- 'fail permission denied': 指定的 fd 没有写权限- 'fail the maximum size of the file storage limit is exceeded': 存储空间不足- 'fail sdcard not mounted android sdcard': 挂载失败
文件读取的起始位置,如不传或传 null,则会从当前文件指针的位置读取。如果 position 是正整数,则文件指针位置会保持不变并从 position 读取文件。
complete
(res: TaroGeneral.CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: ReadFailCallbackResult) => void
否
接口调用失败的回调函数
success
(res: ReadSuccessCallbackResult) => void
否
接口调用成功的回调函数
ReadFailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'bad file descriptor': 无效的文件描述符- 'fail permission denied': 指定的 fd 路径没有读权限- 'fail the value of "offset" is out of range': 传入的 offset 不合法- 'fail the value of "length" is out of range': 传入的 length 不合法- 'fail sdcard not mounted': android sdcard 挂载失败- 'bad file descriptor': 无效的文件描述符
ReadSuccessCallbackResult
参数
类型
说明
bytesRead
string
实际读取的字节数
arrayBuffer
ArrayBuffer
被写入的缓存区的对象,即接口入参的 arrayBuffer
errMsg
string
调用结果
readCompressedFile
Promised
tsx
FailCallbackResult | SuccessCallbackResult
Option
参数
类型
必填
说明
filePath
string
是
要读取的文件的路径 (本地用户文件或代码包文件)
compressionAlgorithm
string
是
文件压缩类型,目前仅支持 'br'。
complete
(res: TaroGeneral.CallbackResult) => void
否
接口调用结束的回调函数(调用成功、失败都会执行)
fail
(result: FailCallbackResult) => void
否
接口调用失败的回调函数
success
(res: SuccessCallbackResult) => void
否
接口调用成功的回调函数
CompressionAlgorithm
文件压缩类型合法值
参数
说明
br
brotli压缩文件
FailCallbackResult
参数
类型
说明
errMsg
string
错误信息可选值:- 'fail decompress fail': 指定的 compressionAlgorithm 与文件实际压缩格式不符- 'fail no such file or directory, open ${filePath}': 指定的 filePath 所在目录不存在- 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有读权限
错误信息可选值:- 'fail no such file or directory, open ${filePath}': 指定的 filePath 所在目录不存在- 'fail illegal operation on a directory, open "${filePath}"': 指定的 filePath 是一个已经存在的目录- 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有写权限- 'fail the maximum size of the file storage limit is exceeded': 存储空间不足- 'fail sdcard not mounted': android sdcard 挂载失败