# uni.getFileSystemManager()

获取文件管理器

# getFileSystemManager 兼容性

Web 微信小程序 Android iOS HarmonyOS
x 4.41 3.9.0 4.11 4.61

文件管理器对象,用于操作应用可访问的本地文件空间,在app平台是应用沙盒目录。

可实现目录和文件的创建、删除、改名或改路径、遍历目录、获取文件信息、读写文件。

注意:

  • DCloud-DCloud_uni-uni_开头的目录和文件是保留目录。开发者自用的文件目录需避免使用这些前缀;

  • 读取文件API受具体设备内存大小限制,为了在老旧设备具备更好的兼容性,请避免一次性读取大文件的情(建议文件大小不要超过16M);

  • ReadFileSuccessResult 的data参数以前类型是string,Android平台4.31、iOS平台4.61起为了同时支持arraybuffer,类型改成了‘string | ArrayBuffer’,请在使用时手动as为指定类型;

  • app-ios平台4.11版本之前支持的api仅支持在uvue文件中使用文件管理器对象,uts插件中暂不支持; app-ios平台4.61版本后,所有api都支持在uts插件和uvue文件中使用,具体请查看兼容性;

# 返回值

类型
FileSystemManager

# FileSystemManager 的方法

# readFile(options: ReadFileOptions): void;

读取本地文件内容

# readFile 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 3.9.0 4.11 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options ReadFileOptions - - -
名称 类型 必备 默认值 兼容性 描述
encoding string - - base64 / utf-8 / ascii,指定读取文件的字符编码,(iOS平台4.61及以后、Android平台4.31及以后)如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容
合法值 兼容性 描述
ascii - ascii 字符编码
base64 - base64 字符编码
utf-8 - utf-8 字符编码,默认值
filePath string.URIString - - 文件路径,支持相对地址和绝对地址,app-android平台支持代码包文件目录
success (res: ReadFileSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 通用的错误返回结果回调
complete (res: any) => void - - 通用的结束返回结果回调
# ReadFileSuccessResult 的属性值
名称 类型 必备 默认值 兼容性 描述
data string | ArrayBuffer -
读取的内容,类型为 String 或 ArrayBuffer,在4.31以前类型是string,Android平台4.31、iOS平台4.61起支持ArrayBuffer
# IFileSystemManagerFail 的属性值
名称 类型 必备 默认值 兼容性 描述
errCode number - - 错误码
合法值 兼容性 描述
1200002
类型错误。仅支持 base64 / utf-8 / ascii
1300002
未找到文件
1300009
文件描述符错误
1300010
重试
1300011
错误的地址
1300012
操作阻塞
1300013
无权限
1300014
网络不可达
1300015
未知错误
1300016
不是文件夹
1300017
文本文件繁忙
1300018
文件太大
1300019
只读文件系统
1300020
文件名称太长
1300021
是目录
1300022
参数无效
1300033
过多符号链接
1300066
目录非空
1300201
系统错误
1300202
超出文件存储限制的最大尺寸
1301003
对目录的非法操作
1301005
文件已存在
1301111
brotli解压失败
1302003
标志无效
errSubject string - - 统一错误主题(模块)名称
data any - - 错误信息中包含的数据
cause Error - - 源错误信息,可以包含多个错误,详见SourceError
errMsg string - - -

# readFileSync(filePath: string, encoding?: string): string | ArrayBuffer;

FileSystemManager.readFile 的同步版本参数

# readFileSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
filePath string - - 文件路径,支持相对地址和绝对地址,app-android平台支持代码包文件目录
encoding string - - base64 / utf-8,指定读取文件的字符编码,(iOS平台4.61及以后、Android平台4.31及以后)如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容
# 返回值
类型
string | ArrayBuffer

# writeFile(options: WriteFileOptions): void;

写文件

# writeFile 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 3.9.0 4.11 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options WriteFileOptions - - -
名称 类型 必备 默认值 兼容性 描述
filePath string.URIString - - 文件路径,只支持绝对地址
encoding string - - 指定写入文件的字符编码,
支持:ascii base64 utf-8,默认值是 utf-8,仅在 data 类型是 String 时有效
合法值 兼容性 描述
ascii - ascii 编码格式
base64 - base64 编码格式
utf-8 - utf-8 编码格式,默认值
data string | ArrayBuffer -
写入的内容,类型为 String 或 ArrayBuffer,之前类型是string,iOS平台4.61及以后、Android平台4.31及以后支持ArrayBuffer类型
success (res: FileManagerSuccessResult) => void - - 通用的正确返回结果回调
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# read(option: ReadOption): void;

读文件

# read 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.31 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
option ReadOption - - -
名称 类型 必备 默认值 兼容性 描述
arrayBuffer ArrayBuffer - - 数据写入的缓冲区,必须是 ArrayBuffer 实例
fd string - - 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得
length number - - 要从文件中读取的字节数,默认0
offset number - - 缓冲区中的写入偏移量,默认0
position number - - 文件读取的起始位置,如不传或传 null,则会从当前文件指针的位置读取。如果 position 是正整数,则文件指针位置会保持不变并从 position 读取文件。
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
success (result: ReadSuccessCallbackResult) => void - - 接口调用成功的回调函数
# ReadSuccessCallbackResult 的属性值
名称 类型 必备 默认值 兼容性 描述
arrayBuffer ArrayBuffer -
被写入的缓存区的对象,即接口入参的 arrayBuffer
bytesRead number -
实际读取的字节数

# readSync(option: ReadSyncOption): ReadResult;

读文件

# readSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.31 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
option ReadSyncOption - - -
名称 类型 必备 默认值 兼容性 描述
arrayBuffer ArrayBuffer -
数据写入的缓冲区,必须是 ArrayBuffer 实例
fd string - - 文件描述符。fd 通过 FileSystemManager.openFileSystemManager.openSync 接口获得
length number - - 要从文件中读取的字节数,默认0
offset number - - 缓冲区中的写入偏移量,默认0
position number - - 文件读取的起始位置,如不传或传 null,则会从当前文件指针的位置读取。如果 position 是正整数,则文件指针位置会保持不变并从 position 读取文件。
# 返回值
类型
ReadResult
名称 类型 必备 默认值 兼容性 描述
arrayBuffer ArrayBuffer -
被写入的缓存区的对象,即接口入参的 arrayBuffer
bytesRead number -
实际读取的字节数

# writeFileSync(filePath: string, data: string | ArrayBuffer, encoding?: string): void;

FileSystemManager.writeFile 的同步版本

# writeFileSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.51
# 参数
名称 类型 必填 默认值 兼容性 描述
filePath string - - 文件路径,只支持绝对地址
data string | ArrayBuffer - - 要写入的文本或二进制数据,Android平台4.31、iOS平台4.61及以后版本支持ArrayBuffer
encoding string - - 指定写入文件的字符编码,支持:ascii base64 utf-8, 默认值是utf-8, 仅在 data 类型是 String 时有效

删除文件

Web 微信小程序 Android iOS HarmonyOS
x 4.41 3.9.0 4.11 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options UnLinkOptions - - -
名称 类型 必备 默认值 兼容性 描述
filePath string.URIString - - 文件路径,只支持绝对地址
success (res: FileManagerSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# unlinkSync(filePath: string): void;

FileSystemManager.unlink 的同步版本

# unlinkSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
filePath string - - 文件路径,只支持绝对地址

# mkdir(options: MkDirOptions): void;

创建目录

# mkdir 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 3.9.0 4.11 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options MkDirOptions - - -
名称 类型 必备 默认值 兼容性 描述
dirPath string.URIString - - 创建的目录路径 (本地路径)
recursive boolean - - 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。
success (res: FileManagerSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# mkdirSync(dirPath: string, recursive: boolean): void;

FileSystemManager.mkdir 的同步版本

# mkdirSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
dirPath string - - 创建的目录路径 (本地路径)
recursive boolean - - 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。

# rmdir(options: RmDirOptions): void;

删除目录

# rmdir 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 3.9.0 4.11 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options RmDirOptions - - -
名称 类型 必备 默认值 兼容性 描述
dirPath string.URIString - - 要删除的目录路径 (本地路径)
recursive boolean - - 是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。
success (res: FileManagerSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# rmdirSync(dirPath: string, recursive: boolean): void;

FileSystemManager.rmdir 的同步版本

# rmdirSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
dirPath string - - 要删除的目录路径 (本地路径)
recursive boolean - - 是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。

# readdir(options: ReadDirOptions): void;

读取目录内文件列表

# readdir 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 3.9.0 4.11 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options ReadDirOptions - - -
名称 类型 必备 默认值 兼容性 描述
dirPath string.URIString - - 要读取的目录路径 (本地路径)
success (res: ReadDirSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)
# ReadDirSuccessResult 的属性值
名称 类型 必备 默认值 兼容性 描述
files Array<string> - - -

# readdirSync(dirPath: string): string[] | null;

FileSystemManager.readdir 的同步版本

# readdirSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
dirPath string - - 要读取的目录路径 (本地路径)
# 返回值
类型 必备
Array<string>

# access(options: AccessOptions): void;

判断文件/目录是否存在

# access 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 3.9.0 4.11 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options AccessOptions - - -
名称 类型 必备 默认值 兼容性 描述
path string.URIString - - 要判断是否存在的文件/目录路径 (本地路径)
success (res: FileManagerSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# accessSync(path: string): void;

FileSystemManager.access 的同步版本

# accessSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
path string - - 要判断是否存在的文件/目录路径 (本地路径)

# rename(options: RenameOptions): void;

重命名文件。可以把文件从 oldPath 移动到 newPath

# rename 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 3.9.0 4.11 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options RenameOptions - - -
名称 类型 必备 默认值 兼容性 描述
oldPath string.URIString - - 源文件路径,支持本地路径
newPath string.URIString - - 新文件路径,支持本地路径
success (res: FileManagerSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# renameSync(oldPath: string, newPath: string): void;

FileSystemManager.rename 的同步版本

# renameSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
oldPath string - - 源文件路径,支持本地路径
newPath string - - 新文件路径,支持本地路径

# copyFile(options: CopyFileOptions): void;

复制文件

# copyFile 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options CopyFileOptions - - -
名称 类型 必备 默认值 兼容性 描述
srcPath string.URIString - - 源文件路径,支持本地路径
destPath string.URIString - - 新文件路径,支持本地路径
success (res: FileManagerSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# copyFileSync(srcPath: string, destPath: string): void;

FileSystemManager.copyFile 的同步版本

# copyFileSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
srcPath string - - 源文件路径,支持本地路径
destPath string - - 新文件路径,支持本地路径

# getFileInfo(options: GetFileInfoOptions): void;

获取该本地临时文件 或 本地缓存文件 信息

# getFileInfo 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 3.9.0 4.11 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options GetFileInfoOptions - - -
名称 类型 必备 默认值 兼容性 描述
filePath string.URIString - - 要读取的文件路径 (本地路径)
digestAlgorithm string - - 计算文件摘要的算法
合法值 兼容性 描述
md5 - md5 算法
sha1 - sha1 算法
success (res: GetFileInfoSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)
# GetFileInfoSuccessResult 的属性值
名称 类型 必备 默认值 兼容性 描述
digest string - - 按照传入的 digestAlgorithm 计算得出的的文件摘要
size number - - 文件大小,以字节为单位

# stat(options: StatOptions): void;

获取文件 Stats 对象

# stat 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 3.9.0 4.11 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options StatOptions - - -
名称 类型 必备 默认值 兼容性 描述
path string.URIString - - 文件/目录路径 (本地路径)
recursive boolean - - 是否递归获取目录下的每个文件的 Stats 信息
success (res: StatSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)
# StatSuccessResult 的属性值
名称 类型 必备 默认值 兼容性 描述
stats Array<FileStats> - - -
名称 类型 必备 默认值 兼容性 描述
path string - - 文件/目录路径
stats Stats - - Stats 对象,即描述文件状态的对象
名称 类型 必备 默认值 兼容性 描述
mode number - - 文件的类型和存取的权限,对应 POSIX stat.st_mode
注意android中,文件类型只包含是否是目录与文件,
另外在android中这里的权限指的是当前进程对文件或者文件夹是否有读,写,执行的权限,
这里没有与 POSIX stat.st_mode对应的组,其他人等相关权限的数据返回,只有所有者的相关权限
size number - - 文件大小,单位:B,对应 POSIX stat.st_size
lastAccessedTime number - - 文件最近一次被存取或被执行的时间,UNIX 时间戳,对应 POSIX stat.st_atime
注意:android中由于系统限制无法获取该数据
lastModifiedTime number - - 文件最后一次被修改的时间,UNIX 时间戳,对应 POSIX stat.st_mtime
# Stats 的方法
# isDirectory(): boolean;

判断当前文件是否一个目录

# isDirectory 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.31 4.11 4.61
# 返回值
类型
boolean
# isFile: isDirectory(): boolean;

判断当前文件是否一个普通文件

# isFile 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.31 4.11 4.61
# 返回值
类型
boolean

# statSync(path : string, recursive : boolean) : Array<Map<string, any>>;

FileSystemManager.stat 的同步版本

# statSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
path string - - 文件/目录路径 (本地路径)
recursive boolean - - 是否递归获取目录下的每个文件的 Stats 信息
# 返回值
类型
Array<Map<string, any>>

# appendFile(options: AppendFileOptions): void;

在文件结尾追加内容

# appendFile 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options AppendFileOptions - - -
名称 类型 必备 默认值 兼容性 描述
filePath string.URIString - - 要追加内容的文件路径 (本地路径)
encoding string - - 指定写入文件的字符编码
支持:ascii base64 utf-8
只在 data 类型是 String 时有效
合法值 兼容性 描述
ascii - ascii字符编码
base64 - base64字符编码
utf-8 - utf-8字符编码,默认值
data string | ArrayBuffer -
要追加的文本或二进制数据,类型为 String 或 ArrayBuffer,以前类型是string,iOS平台4.61、Android平台4.31及以后支持arraybuffer
success (res: FileManagerSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# appendFileSync(filePath: string, data: string | ArrayBuffer, encoding?: string): void;

FileSystemManager.appendFile 的同步版本

# appendFileSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
filePath string - - 要追加内容的文件路径 (本地路径)
data string | ArrayBuffer - - 要追加的文本或二进制数据,类型为 String 或 ArrayBuffer,Android平台4.31、iOS平台4.61之前前类型是string,Android平台4.31、iOS平台4.61起支持ArrayBuffer
encoding string - - 指定写入文件的字符编码支持:ascii base64 utf-8,只在 data 类型是 String 时有效

# saveFile(options: SaveFileOptions): void;

保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。

# saveFile 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options SaveFileOptions - - -
名称 类型 必备 默认值 兼容性 描述
tempFilePath string.URIString - - 临时存储文件路径 (本地路径)
filePath string.URIString - - 要存储的文件路径 (本地路径)
success (res: SaveFileSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)
# SaveFileSuccessResult 的属性值
名称 类型 必备 默认值 兼容性 描述
savedFilePath string - - 存储后的文件路径 (本地路径)

# saveFileSync(tempFilePath: string, filePath: string | null): string;

FileSystemManager.saveFile 的同步版本

# saveFileSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
tempFilePath string - - 临时存储文件路径 (本地路径)
filePath string - - 要存储的文件路径 (本地路径)
# 返回值
类型
string

# removeSavedFile(options: RemoveSavedFileOptions): void;

删除该小程序下已保存的本地缓存文件

# removeSavedFile 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options RemoveSavedFileOptions - - -
名称 类型 必备 默认值 兼容性 描述
filePath string.URIString - - 需要删除的文件路径 (本地路径)
success (res: FileManagerSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# unzip(options: UnzipFileOptions): void;

解压文件

# unzip 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options UnzipFileOptions - - -
名称 类型 必备 默认值 兼容性 描述
zipFilePath string - - 源文件路径,支持本地路径, 只可以是 zip 压缩文件
targetPath string - - 目标目录路径, 支持本地路径
success (res: FileManagerSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# getSavedFileList(options: GetSavedFileListOptions): void;

获取该已保存的本地缓存文件列表

# getSavedFileList 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options GetSavedFileListOptions - - -
名称 类型 必备 默认值 兼容性 描述
success (res: GetSavedFileListResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)
# GetSavedFileListResult 的属性值
名称 类型 必备 默认值 兼容性 描述
fileList Array<string> - - 文件数组

# truncate(options: TruncateFileOptions): void;

对文件内容进行截断操作

# truncate 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options TruncateFileOptions - - -
名称 类型 必备 默认值 兼容性 描述
filePath string.URIString - - 要截断的文件路径 (本地路径)
length number - - 截断位置,默认0。如果 length 小于文件长度(字节),则只有前面 length 个字节会保留在文件中,其余内容会被删除;
如果 length 大于文件长度,不做处理
success (res: FileManagerSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# truncateSync(filePath: string, length?: number): void;

对文件内容进行截断操作 (truncate 的同步版本)

# truncateSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
filePath string - - 要截断的文件路径 (本地路径)
length number - - 截断位置,默认0。如果 length 小于文件长度(字节),则只有前面 length 个字节会保留在文件中,其余内容会被删除;如果 length 大于文件长度,不做处理

# readCompressedFile(options: ReadCompressedFileOptions): void;

读取指定压缩类型的本地文件内容

# readCompressedFile 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options ReadCompressedFileOptions - - -
名称 类型 必备 默认值 兼容性 描述
filePath string.URIString - - 要读取的文件的路径 (本地用户文件或代码包文件),app-android平台支持代码包文件目录
compressionAlgorithm string - - 文件压缩类型,目前仅支持 'br'。
success (res: ReadCompressedFileResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)
# ReadCompressedFileResult 的属性值
名称 类型 必备 默认值 兼容性 描述
data string - - -

# readCompressedFileSync(filePath: string, compressionAlgorithm: string): string

同步读取指定压缩类型的本地文件内容

# readCompressedFileSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
filePath string - - 要读取的文件的路径 (本地用户文件或代码包文件),app-android平台支持代码包文件目录
compressionAlgorithm string - - 文件压缩类型,目前仅支持 'br'。
# 返回值
类型
string

# open(options: OpenFileOptions): void;

打开文件,返回文件描述符

# open 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options OpenFileOptions - - -
名称 类型 必备 默认值 兼容性 描述
filePath string.URIString - - 要追加内容的文件路径 (本地路径)
flag string - - 文件系统标志,默认值: 'r'
合法值 兼容性 描述
a - 打开文件用于追加。 如果文件不存在,则创建该文件
ax - 类似于 'a',但如果路径存在,则失败
a+ - 打开文件用于读取和追加。 如果文件不存在,则创建该文件
ax+ - 类似于 'a+',但如果路径存在,则失败
r - 打开文件用于读取。 如果文件不存在,则会发生异常
r+ - 打开文件用于读取和写入。 如果文件不存在,则会发生异常
w - 打开文件用于写入。 如果文件不存在则创建文件,如果文件存在则截断文件
wx - 类似于 'w',但如果路径存在,则失败
w+ - 打开文件用于读取和写入。 如果文件不存在则创建文件,如果文件存在则截断文件
wx+ - 类似于 'w+',但如果路径存在,则失败
success (res: OpenFileSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)
# OpenFileSuccessResult 的属性值
名称 类型 必备 默认值 兼容性 描述
fd string - - 文件描述符

# openSync(options: OpenFileSyncOptions): string;

同步打开文件,返回文件描述符

# openSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options OpenFileSyncOptions - - -
名称 类型 必备 默认值 兼容性 描述
filePath string.URIString - - 要追加内容的文件路径 (本地路径)
flag string - - 文件系统标志,默认值: 'r'
合法值 兼容性 描述
a - 打开文件用于追加。 如果文件不存在,则创建该文件
ax - 类似于 'a',但如果路径存在,则失败
a+ - 打开文件用于读取和追加。 如果文件不存在,则创建该文件
ax+ - 类似于 'a+',但如果路径存在,则失败
r - 打开文件用于读取。 如果文件不存在,则会发生异常
r+ - 打开文件用于读取和写入。 如果文件不存在,则会发生异常
w - 打开文件用于写入。 如果文件不存在则创建文件,如果文件存在则截断文件
wx - 类似于 'w',但如果路径存在,则失败
w+ - 打开文件用于读取和写入。 如果文件不存在则创建文件,如果文件存在则截断文件
wx+ - 类似于 'w+',但如果路径存在,则失败
# 返回值
类型
string

# write(options: WriteOptions): void;

写入文件

# write 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options WriteOptions - - -
名称 类型 必备 默认值 兼容性 描述
fd string - - 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得
data string | ArrayBuffer - - 写入的内容,类型为 String 或 ArrayBuffer,以前类型是string,iOS平台4.61、Android平台4.31及以后支持ArrayBuffer
offset number 0
Android平台4.31及以后版本新增,只在 data 类型是 ArrayBuffer 时有效,决定 ArrayBuffer 中要被写入的部位,即 ArrayBuffer 中的索引,默认0
length number -
Android平台4.31及以后版本新增,只在 data 类型是 ArrayBuffer 时有效,指定要写入的字节数,默认为 ArrayBuffer 从0开始偏移 offset 个字节后剩余的字节数
position number -
Andorid平台4.31及以后版本新增,指定文件开头的偏移量,即数据要被写入的位置。当 position 不传或者传入非 Number 类型的值时,数据会被写入当前指针所在位置。
encoding string - - 只在 data 类型是 String 时有效,指定写入文件的字符编码,默认为 utf8
支持:ascii base64 utf-8
合法值 兼容性 描述
ascii - ascii 字符编码
base64 - base64 字符编码
utf-8 - utf-8 字符编码,默认值
success (res: WriteResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)
# WriteResult 的属性值
名称 类型 必备 默认值 兼容性 描述
bytesWritten number - - 实际被写入到文件中的字节数(注意,被写入的字节数不一定与被写入的字符串字符数相同)

# writeSync(options: WriteSyncOptions): WriteResult;

同步写入文件

# writeSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options WriteSyncOptions - - -
名称 类型 必备 默认值 兼容性 描述
fd string - - 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得
data string | ArrayBuffer -
写入的内容,类型为 String 或 ArrayBuffer,在4.31以前类型是string,4.31起为了同时支持ArrayBuffer
encoding string - - 只在 data 类型是 String 时有效,指定写入文件的字符编码,默认为 utf8
支持:ascii base64 utf-8
合法值 兼容性 描述
ascii - ascii 字符编码
base64 - base64 字符编码
utf-8 - utf-8 字符编码,默认值
length number -
只在 data 类型是 ArrayBuffer 时有效,指定要写入的字节数,默认为 arrayBuffer 从0开始偏移 offset 个字节后剩余的字节数 ,4.31及以后版本新增
offset number -
只在 data 类型是 ArrayBuffer 时有效,决定 arrayBuffe 中要被写入的部位,即 arrayBuffer 中的索引,默认0,4.31及以后版本新增
position number -
指定文件开头的偏移量,即数据要被写入的位置。当 position 不传或者传入非 Number 类型的值时,数据会被写入当前指针所在位置。4.31及以后版本新增
# 返回值
类型
WriteResult

# close(options: CloseOptions): void;

关闭文件

# close 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options CloseOptions - - -
名称 类型 必备 默认值 兼容性 描述
fd string - - 需要被关闭的文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得
success (res: FileManagerSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# closeSync(options: CloseSyncOptions): void;

同步关闭文件

# closeSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options CloseSyncOptions - - -
名称 类型 必备 默认值 兼容性 描述
fd string - - 需要被关闭的文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得

# fstat(options: FStatOptions): void;

获取文件的状态信息

# fstat 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options FStatOptions - - -
名称 类型 必备 默认值 兼容性 描述
fd string - - 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得
success (res: FStatSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)
# FStatSuccessResult 的属性值
名称 类型 必备 默认值 兼容性 描述
stats Stats - - Stats 对象,包含了文件的状态信息

# fstatSync(options: FStatSyncOptions): Stats;

同步获取文件的状态信息

# fstatSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options FStatSyncOptions - - -
名称 类型 必备 默认值 兼容性 描述
fd string - - 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得
# 返回值
类型 描述
Stats Stats 对象,包含了文件的状态信息

# ftruncate(options: FTruncateFileOptions): void;

对文件内容进行截断操作

# ftruncate 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options FTruncateFileOptions - - -
名称 类型 必备 默认值 兼容性 描述
fd string - - 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得
length number - - 截断位置,默认0。如果 length 小于文件长度(字节),则只有前面 length 个字节会保留在文件中,其余内容会被删除;
如果 length 大于文件长度,不做处理
success (res: FileManagerSuccessResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)

# ftruncateSync(options: FTruncateFileSyncOptions): void;

同步对文件内容进行截断操作

# ftruncateSync 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options FTruncateFileSyncOptions - - -
名称 类型 必备 默认值 兼容性 描述
fd string - - 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得
length number - - 截断位置,默认0。如果 length 小于文件长度(字节),则只有前面 length 个字节会保留在文件中,其余内容会被删除;
如果 length 大于文件长度,不做处理

# readZipEntry(options: ReadZipEntryOptions): void;

读取压缩包内的文件

# readZipEntry 兼容性
Web 微信小程序 Android iOS HarmonyOS
x 4.41 4.13 4.61 4.61
# 参数
名称 类型 必填 默认值 兼容性 描述
options ReadZipEntryOptions - - -
名称 类型 必备 默认值 兼容性 描述
filePath string.URIString - - 要读取的压缩包的路径 (本地路径),app-android平台支持代码包文件目录
encoding string - - 统一指定读取文件的字符编码,只在 entries 值为"all"时有效。
4.31及以后版本如果 entries 值为 null 且不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容
合法值 兼容性 描述
ascii - ascii 字符编码
base64 - base64 字符编码
utf-8 - utf-8 字符编码,默认值
entries Array<EntryItem> - - 要读取的压缩包内的文件列表(当不传入时表示读取压缩包内所有文件)
名称 类型 必备 默认值 兼容性 描述
path string - - 压缩包内文件路径
encoding string - - 指定写入文件的字符编码
支持:ascii base64 utf-8;4.31及以后版本如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容
合法值 兼容性 描述
ascii - ascii 字符编码
base64 - base64 字符编码
utf-8 - utf-8 字符编码,默认值
success (res: EntriesResult) => void - - 接口调用的回调函数
fail (res: IFileSystemManagerFail) => void - - 接口调用失败的回调函数
complete (res: any) => void - - 接口调用结束的回调函数(调用成功、失败都会执行)
# EntriesResult 的属性值
名称 类型 必备 默认值 兼容性 描述
entries Map<string, ZipFileItem> - - 文件路径
result Map<string, ZipFileItem> - - 已废弃,使用 entries

# 特殊说明

  • app-ios平台4.11版本之前支持的api仅支持在uvue文件中使用文件管理器对象,uts插件中暂不支持; 4.61版本后,所有api都支持在uts插件和uvue文件中使用,具体请查看兼容性

  • app-android平台API不支持代码包文件目录

  • app-android平台content:// 路径文件是只读的

# 参见

# 示例

hello uni-app x

该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验

扫码体验(手机浏览器跳转到App直达页)
<template>
  <!-- #ifdef APP -->
  <text>显示简易操作日志(可滚动查看),详细日志需真机运行查看</text><button size="mini" @click="log=''">清空日志</button>
  <scroll-view style="max-height: 300px;">
    <text style="margin: 2px; padding: 2px; border: 1px solid #000000;">{{ log }}</text>
  </scroll-view>
  <scroll-view style="flex: 1;">
  <!-- #endif -->
    <!-- #ifdef MP -->
    <text style="margin: 2px; padding: 2px; border: 1px solid #000000;">{{ log }}</text>
    <!-- #endif -->
    <button class="btnstyle" type="primary" @tap="statFileInfoTest"
      id="btn-stat-file">递归获取目录files的Stats对象{{statFile}}</button>
    <button class="btnstyle" type="primary" @tap="mkdirTest" id="btn-mkdir">创建文件夹{{mkdirFile}}</button>
    <button class="btnstyle" type="primary" @tap="writeFileTest" id="btn-write-file">覆盖写入文件{{writeFile}}</button>
    <button class="btnstyle" type="primary" @tap="readDirTest" id="btn-read-dir">读取文件夹{{readDir}}</button>
    <button class="btnstyle" type="primary" @tap="readFileTest" id="btn-read-file">读取文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="copyFileTest"
      id="btn-copy-file">复制文件{{copyFromFile}}到{{copyToFile}}</button>
    <button class="btnstyle" type="primary" @tap="renameFileTest"
      id="btn-rename-file">重命名文件{{renameFromFile}}到{{renameToFile}}</button>
    <button class="btnstyle" type="primary" @tap="accessFileTest" id="btn-access-file">判断文件{{accessFile}}是否存在</button>
    <button class="btnstyle" type="primary" @tap="getFileInfoTest"
      id="btn-get-file-info">获取文件信息{{getFileInfoFile}}</button>
    <button class="btnstyle" type="primary" @tap="unlinkTest" id="btn-unlink-file">删除文件{{unlinkFile}}</button>
    <!-- #ifdef APP -->
    <button class="btnstyle" type="primary" @tap="copyStaticToFilesTest"
      id="btn-copyStatic-file">从static目录复制文件到a目录</button>
    <!-- #endif -->
    <button class="btnstyle" type="primary" @tap="unlinkAllFileTest"
      id="btn-clear-file">删除文件夹{{rmDirFile}}下的所有文件</button>
    <button class="btnstyle" type="primary" @tap="rmdirTest" id="btn-remove-dir">删除文件夹{{rmDirFile}}</button>


    <!-- #ifdef APP || MP -->
    <button class="btnstyle" type="primary" @tap="statFileInfoSyncTest"
      id="btn-stat-file-sync">同步递归获取目录files的Stats对象{{statFile}}</button>
    <button class="btnstyle" type="primary" @tap="appendFileTest" id="btn-append-file">在文件{{readFile}}结尾追加内容</button>
    <button class="btnstyle" type="primary" @tap="appendFileSyncTest"
      id="btn-append-file-sync">同步在文件{{readFile}}结尾追加内容</button>
    <button class="btnstyle" type="primary" @tap="writeFileSyncTest"
      id="btn-write-file-sync">同步覆盖写入文件{{writeFile}}</button>
    <button class="btnstyle" type="primary" @tap="readFileSyncTest" id="btn-read-file-sync">同步读取文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="unlinkSyncTest"
      id="btn-unlink-file-sync">同步删除文件{{unlinkFile}}</button>
    <button class="btnstyle" type="primary" @tap="mkdirSyncTest" id="btn-mkdir-sync">同步创建文件夹{{mkdirFile}}</button>
    <button class="btnstyle" type="primary" @tap="rmdirSyncTest" id="btn-remove-dir-sync">同步删除文件夹{{rmDirFile}}</button>
    <button class="btnstyle" type="primary" @tap="readDirSyncTest" id="btn-read-dir-sync">同步读取文件夹{{readDir}}</button>
    <button class="btnstyle" type="primary" @tap="accessFileSyncTest"
      id="btn-access-file-sync">同步判断文件{{accessFile}}是否存在</button>
    <button class="btnstyle" type="primary" @tap="renameFileSync"
      id="btn-rename-file-sync">同步重命名文件{{renameFromFile}}到{{renameToFile}}</button>
    <button class="btnstyle" type="primary" @tap="copyFileSyncTest"
      id="btn-copy-file-sync">同步复制文件{{copyFromFile}}到{{copyToFile}}</button>
    <!-- #ifdef APP -->
    <button class="btnstyle" type="primary" @tap="saveFileTest" id="btn-save-file">保存临时文件到本地</button>
    <button class="btnstyle" type="primary" @tap="saveFileSyncTest" id="btn-save-file-sync">同步保存临时文件到本地</button>
    <!-- #endif -->
    <button class="btnstyle" type="primary" @tap="removeSavedFileTest" id="btn-remove-saved-file">删除已保存的本地文件</button>
    <!-- #ifdef APP -->
    <button class="btnstyle" type="primary" @tap="unzipFileTest" id="btn-unzip-file-sync">解压文件</button>
    <!-- #endif -->
    <button class="btnstyle" type="primary" @tap="getSavedFileListTest"
      id="btn-getsaved-filelist">获取该已保存的本地缓存文件列表</button>
    <button class="btnstyle" type="primary" @tap="truncateFileTest"
      id="btn-truncate-file">对文件{{writeFile}}内容进行截断操作</button>
    <!-- #ifdef APP -->
    <button class="btnstyle" type="primary" @tap="truncateFileSyncTest"
      id="btn-truncate-file-sync">同步对文件{{writeFile}}内容进行截断操作</button>

    <button class="btnstyle" type="primary" @tap="readCompressedFileTest"
      id="btn-compressed-file">读取指定压缩类型的本地文件内容</button>
    <button class="btnstyle" type="primary" @tap="readCompressedFileSyncTest"
      id="btn-compressed-file-sync">同步读取指定压缩类型的本地文件内容</button>
    <!-- #endif -->
    <button class="btnstyle" type="primary" @tap="openFileTest" id="btn-open-file">打开文件{{readFile}},返回描述符</button>
    <button class="btnstyle" type="primary" @tap="openFileSyncTest('r',true)"
      id="btn-open-file-sync">同步打开文件{{readFile}},返回描述符</button>
    <button class="btnstyle" type="primary" @tap="closeTest" id="btn-close-file">通过文件描述符关闭文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="closeSyncTest"
      id="btn-close-file-sync">通过文件描述符同步关闭文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="writeTest" id="btn-write">通过文件描述符写入文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="writeSyncTest" id="btn-write-sync">同步通过文件描述符写入文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="fstatTest" id="btn-fstat-file">通过文件描述符获取{{statFile}}的状态信息</button>
    <button class="btnstyle" type="primary" @tap="fstatSyncTest"
      id="btn-fstat-file-sync">同步通过文件描述符获取{{statFile}}的状态信息</button>
    <button class="btnstyle" type="primary" @tap="ftruncateFileTest"
      id="btn-ftruncate-file">通过文件描述符对文件{{writeFile}}内容进行截断</button>
    <button class="btnstyle" type="primary" @tap="ftruncateFileSyncTest"
      id="btn-ftruncate-file-sync">同步通过文件描述符对文件{{writeFile}}内容进行截断</button>
    <!-- #ifdef APP -->
    <button class="btnstyle" type="primary" @tap="readZipEntry" id="btn-readzip-entry">读取压缩包内的文件</button>
    <!-- #endif -->
    <button class="btnstyle" type="primary" @tap="testWriteReadFileBuffer" id="btn-writereadfile-buffer">写入/读取
      ArrayBuffer</button>
    <!-- #ifdef APP -->
    <button class="btnstyle" type="primary" @tap="testWriteReadFileSyncBuffer" id="btn-writereadfilesync-buffer">同步写入/读取
      ArrayBuffer</button>
      <!-- #endif -->
    <button class="btnstyle" type="primary" @tap="testWriteReadBuffer" id="btn-writeread-buffer">通过文件描述符写入/读取
      ArrayBuffer</button>
    <button class="btnstyle" type="primary" @tap="testWriteReadSyncBuffer" id="btn-writereadsync-buffer">通过文件描述符同步写入/读取
      ArrayBuffer</button>
    <button class="btnstyle" type="primary" @tap="testAppendFileBuffer" id="btn-appendfile-buffer">在文件末尾追加
      ArrayBuffer</button>
    <button class="btnstyle" type="primary" @tap="testAppendFileBufferSync" id="btn-appendfilesync-buffer">同步在文件末尾追加
      ArrayBuffer</button>
    <!-- #ifdef APP -->
    <button class="btnstyle" type="primary" @tap="testReadFileEncoding('base64')">readFile(content:// base64)</button>
    <button class="btnstyle" type="primary" @tap="testReadFileEncoding('utf-8')">readFile(content:// utf-8)</button>
    <button class="btnstyle" type="primary" @tap="testReadFileEncoding('ascii')">readFile(content:// ascii)</button>
    <button class="btnstyle" type="primary" @tap="testReadFileArrayBuffer()">readFile(content:// arraybuffer)</button>

    <button class="btnstyle" type="primary" @tap="testReadFileSyncEncoding('base64')">readFileSync(content://
      base64)</button>
    <button class="btnstyle" type="primary" @tap="testReadFileSyncEncoding('utf-8')">readFileSync(content://
      utf-8)</button>
    <button class="btnstyle" type="primary" @tap="testReadFileSyncEncoding('ascii')">readFileSync(content://
      ascii)</button>
    <button class="btnstyle" type="primary" @tap="testReadFileSyncArrayBuffer()">readFileSync(content://
      arraybuffer)</button>

    <button class="btnstyle" type="primary" @tap="copyFileByContent()">copyFile(content://)</button>
    <button class="btnstyle" type="primary" @tap="copyFileSyncByContent()">copyFileSync(content://)</button>
    <!-- #endif -->


    <view style="height: 4px;"></view>
    <!-- #endif -->
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script>
  export default {

    data() {
      return {
        log: "",
        /**
         * 自动化测试需要关闭log
         */
        logAble: true,
        fileListSuccess: [] as string[],
        fileListComplete: [] as string[],
        accessFileRet: '',
        lastFailError: new UniError("uni-file-manager", 1300000, "mock error"),
        lastCompleteError: new UniError("uni-file-manager", 1300000, "mock error"),
        readDir: 'a',
        readFileRet: "",
        writeFileContent: "中文 en.\r\n\t换行",
        appendFileContent: "append content",
        getFileInfoAlgorithm: "md5",
        getFileInfoSize: -1,
        getFileInfoDigest: "",
        unlinkFile: 'a/1.txt',
        accessFile: 'a/1.txt',
        writeFile: 'a/1.txt',
        writeData: 'insert data哈哈哈',
        brFile: 'a/1.txt.br',
        temFile: 'a/1.txt',
        copyFromFile: 'a/1.txt',
        copyToFile: 'a/2.txt',
        renameFromFile: 'a/2.txt',
        renameToFile: 'a/3.txt',
        getFileInfoFile: 'a/1.txt',
        statFile: '',
        rmDirFile: 'a',
        mkdirFile: 'a',
        readFile: 'a/1.txt',
        recursiveVal: true,
        done: false,
        writeFileEncoding: "utf-8",
        readFileEncoding: "utf-8",
        statsRet: [] as Array<FileStats>,
        unzipFile: 'zip/1.zip',
        targetZip: "unzip",
        renameFileRet: '',
        saveFileRet: '',
        removeSavedFileRet: '',
        fd: '',
        closeFileRet: '',
        bytesWritten: 0,
        fstat: null as Stats | null,
        fstatSize: 0,
        ftruncateRet: '',
        readZipFile: 'to.zip',
        getSavedFileListRet: '',
        arrayBufferRes: 0,
        /**
         * 待测试的全局环境变量
         */
        // #ifdef MP
        basePath: uni.env.USER_DATA_PATH + '/',
        copyToBasePath: uni.env.USER_DATA_PATH + '/',
        globalTempPath: uni.env.CACHE_PATH,
        globalRootPath: uni.env.SANDBOX_PATH,
        globalUserDataPath: uni.env.USER_DATA_PATH + '/',
        // #endif
        // #ifndef MP
        basePath: uni.env.USER_DATA_PATH,
        copyToBasePath: uni.env.USER_DATA_PATH,
        globalTempPath: uni.env.CACHE_PATH,
        globalRootPath: uni.env.SANDBOX_PATH,
        globalUserDataPath: uni.env.USER_DATA_PATH,
        // #endif
      }
    },
    onLoad() {
    },

    methods: {
      statFileInfoTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        fileManager.stat({
          path: `${this.basePath}${this.statFile}`, //USER_DATA_PATH
          // path: `${this.globalTempPath}${this.statFile}`, //CACHE_PATH
          recursive: this.recursiveVal,
          success: (res : StatSuccessResult) => {
            if (this.logAble) {
              this.log += 'statFileInfoTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('statFileInfoTest success', res)
            this.statsRet = res.stats
            console.log('this.statsRet', this.statsRet)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'statFileInfoTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('statFileInfoTest fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)
          },
          complete: (res : any) => {
            console.log("statFileInfoTest complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as StatOptions)
      },

      getFileInfoTest: function () {
        const fileManager = uni.getFileSystemManager()

        fileManager.getFileInfo({
          filePath: `${this.basePath}${this.getFileInfoFile}`,
          digestAlgorithm: this.getFileInfoAlgorithm,
          success: (res : GetFileInfoSuccessResult) => {
            if (this.logAble) {
              this.log += 'getFileInfoTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
            this.getFileInfoSize = res.size
            this.getFileInfoDigest = res.digest
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'getFileInfoTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as GetFileInfoOptions)
      },

      copyFileTest: function () {
        const fileManager = uni.getFileSystemManager()

        fileManager.copyFile({
          srcPath: `${this.basePath}${this.copyFromFile}`,
          destPath: `${this.copyToBasePath}${this.copyToFile}`,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as CopyFileOptions)
      },

      renameFileTest: function () {
        const fileManager = uni.getFileSystemManager()

        fileManager.rename({
          oldPath: `${this.basePath}${this.renameFromFile}`,
          newPath: `${this.basePath}${this.renameToFile}`,
          success: (res) => {
            if (this.logAble) {
              this.log += 'renameFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            this.renameFileRet = "rename:ok"
            console.log('success', res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'renameFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)
          },
          complete: (res : any) => {
            this.done = true
            console.log("complete", res)
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as RenameOptions)
      },

      readDirTest: function () {
        const fileManager = uni.getFileSystemManager()
        fileManager.readdir({
          dirPath: `${this.basePath}${this.readDir}`,
          success: (res : ReadDirSuccessResult) => {
            if (this.logAble) {
              this.log += 'readDirTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
            this.fileListSuccess = res.files
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'readDirTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            } else {
              this.fileListComplete = (res as ReadDirSuccessResult).files
            }
          }
        } as ReadDirOptions)
      },

      writeFileTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()

        fileManager.writeFile({
          filePath: `${this.basePath}${this.writeFile}`,
          data: this.writeFileContent,
          encoding: this.writeFileEncoding,
          success: (res) => {
            if (this.logAble) {
              this.log += 'writeFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'writeFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail')
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)
          },
          complete: (res : any) => {
            this.done = true
            console.log("complete")
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }

          }
        } as WriteFileOptions)
      },

      readFileTest: function () {
        const fileManager = uni.getFileSystemManager()

        fileManager.readFile({
          filePath: `${this.basePath}${this.readFile}`,
          encoding: this.readFileEncoding,
          success: (res : ReadFileSuccessResult) => {
            if (this.logAble) {
              this.log += 'readFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
            this.readFileRet = res.data.toString()
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'readFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as ReadFileOptions)
      },

      rmdirTest: function () {
        const fileManager = uni.getFileSystemManager()
        fileManager.rmdir({
          dirPath: `${this.basePath}${this.rmDirFile}`,
          recursive: this.recursiveVal,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'rmdirTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'rmdirTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as RmDirOptions)
      },

      mkdirTest: function () {
        // 准备测试数据
        const fileManager = uni.getFileSystemManager()

        fileManager.mkdir({
          dirPath: `${this.basePath}${this.mkdirFile}`,
          recursive: this.recursiveVal,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'mkdirTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'mkdirTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (res : any) => {
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
            this.done = true
            console.log("complete", res)
          }
        } as MkDirOptions)

      },
      accessFileTest: function () {
        this.accessFileRet = ''
        const fileManager = uni.getFileSystemManager()
        fileManager.access({
          path: `${this.basePath}${this.accessFile}`,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'accessFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
            this.accessFileRet = res.errMsg
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'accessFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (res : any) => {
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
            console.log("complete", res)
            this.done = true
          }
        } as AccessOptions)

      },
      unlinkTest: function () {
        const fileManager = uni.getFileSystemManager()

        fileManager.unlink({
          filePath: `${this.basePath}${this.unlinkFile}`,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'unlinkTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'unlinkTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (res : any) => {
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
            console.log("complete", res)
            this.done = true
          }
        } as UnLinkOptions)
      },
      unlinkAllFileTest: function () {
        const fileManager = uni.getFileSystemManager()
        fileManager.readdir({
          dirPath: `${this.basePath}${this.rmDirFile}`,
          success: (res : ReadDirSuccessResult) => {
            console.log("success to readdir", res)
            res.files.forEach(element => {
              console.log(element)
              let filePath : string
              if (this.rmDirFile.length <= 0) {
                filePath = `${this.basePath}${element}`
              } else {
                filePath = `${this.basePath}${this.rmDirFile}/${element}`
              }
              fileManager.unlink({
                filePath: filePath,
                success: (res : FileManagerSuccessResult) => {
                  if (this.logAble) {
                    this.log += 'unlinkAllFileTest success:' + JSON.stringify(res) + '\n\n'
                  }
                  console.log('success unlink', res)
                },
                fail: (res : IUniError) => {
                  if (this.logAble) {
                    this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
                  }
                  console.log('fail unlink', res)
                  this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

                },
                complete: (res : any) => {
                  if (res instanceof UniError) {
                    this.lastCompleteError = res
                  }
                  console.log("complete unlink", res)
                  this.done = true
                }
              } as UnLinkOptions)
            });
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail to readdir', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (res : any) => {
            console.log("complete readdir", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            } else {
              this.fileListComplete = (res as ReadDirSuccessResult).files
            }
          }
        } as ReadDirOptions)
      },
      copyStaticToFilesTest: function () {
        const fileManager = uni.getFileSystemManager()

        fileManager.copyFile({
          srcPath: "/static/list-mock/mock.json",
          destPath: `${this.copyToBasePath}/a/mock.json`,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as CopyFileOptions)
      },
      //start
      appendFileTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        fileManager.appendFile({
          filePath: `${this.basePath}${this.writeFile}`,
          data: this.appendFileContent,
          encoding: this.writeFileEncoding,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'appendFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'appendFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail')
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (res : any) => {
            this.done = true
            console.log("complete")
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }

          }
        } as AppendFileOptions)
      },
      writeFileSyncTest: function (_ : any) {
        try {
          const fileManager = uni.getFileSystemManager()
          fileManager.writeFileSync(`${this.basePath}${this.writeFile}`, this.writeFileContent, this.writeFileEncoding)
          if (this.logAble) {
            this.log += 'writeFileSyncTest success:' + '\n\n'
          }
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'writeFileSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }

      },
      readFileSyncTest: function () {
        try {
          const fileManager = uni.getFileSystemManager()
          let data = fileManager.readFileSync(
            `${this.basePath}${this.readFile}`,
            this.readFileEncoding)
          if (this.logAble) {
            this.log += 'readFileSyncTest result:' + data + '\n\n'
          }
          this.done = true
          this.readFileRet = data.toString()
        } catch (e) {
          if (this.logAble) {
            this.log += 'readFileSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }

      },
      unlinkSyncTest: function () {
        try {
          const fileManager = uni.getFileSystemManager()
          fileManager.unlinkSync(
            `${this.basePath}${this.unlinkFile}`)
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'unlinkSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      mkdirSyncTest: function () {
        // 准备测试数据
        try {
          const fileManager = uni.getFileSystemManager()
          fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, this.recursiveVal)
          this.done = true
        } catch (e) {
          this.done = true
          if (this.logAble) {
            this.log += 'mkdirSyncTest fail:' + e + '\n\n'
          }
        }

      },
      rmdirSyncTest: function () {
        try {
          const fileManager = uni.getFileSystemManager()
          fileManager.rmdirSync(
            `${this.basePath}${this.rmDirFile}`,
            this.recursiveVal)
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      readDirSyncTest: function () {
        try {
          const fileManager = uni.getFileSystemManager()
          let res = fileManager.readdirSync(
            `${this.basePath}${this.readDir}`)
          if (this.logAble) {
            this.log += 'readDirTest success:' + JSON.stringify(res) + '\n\n'
          }
          if (res != null) {
            this.fileListSuccess = res
          }
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      accessFileSyncTest: function () {
        this.accessFileRet = ''
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.accessSync(`${this.basePath}${this.accessFile}`)
          this.done = true
          this.accessFileRet = 'access:ok'
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      renameFileSync: function () {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.renameSync(`${this.basePath}${this.renameFromFile}`,
            `${this.basePath}${this.renameToFile}`)
          this.done = true
          this.renameFileRet = "rename:ok"

        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          console.log('renameSync:' + e)
          this.done = true
        }
      },
      copyFileSyncTest: function () {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.copyFileSync(
            `${this.basePath}${this.copyFromFile}`,
            `${this.copyToBasePath}${this.copyToFile}`)
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      appendFileSyncTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.appendFileSync(
            `${this.basePath}${this.writeFile}`,
            this.appendFileContent,
            this.writeFileEncoding)
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      saveFileTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        fileManager.saveFile({
          tempFilePath: `${this.basePath}${this.temFile}`,
          // filePath:`${this.basePath}local/`,
          success: (res : SaveFileSuccessResult) => {
            if (this.logAble) {
              this.log += 'saveFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
            this.saveFileRet = res.savedFilePath
            this.done = true
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'saveFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('saveFileTest fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

            this.done = true
          },
          complete: (_) => {
            this.done = true
          }
        } as SaveFileOptions)
      },
      saveFileSyncTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.saveFileSync(
            `${this.basePath}${this.temFile}`, `${this.basePath}/`)
          // filePath:`${this.basePath}local/`,)
          this.done = true

          //todo 后面打开
          // this.saveFileRet=res
        } catch (e) {
          console.log('saveFileSyncTest:' + e)
          this.done = true
        }
      },
      unzipFileTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.mkdirSync(`${this.basePath}${this.targetZip}`, true)
        } catch (e) {
          console.error(e)
        }
        fileManager.unzip({
          zipFilePath: '/static/filemanager/to.zip',
          targetPath: `${this.basePath}${this.targetZip}`,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'unzipFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'unzipFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (_) => {
            this.done = true
          }
        } as UnzipFileOptions)
      },

      getSavedFileListTest: function () {
        const fileManager = uni.getFileSystemManager()
        fileManager.getSavedFileList({
          success: (res : GetSavedFileListResult) => {
            if (this.logAble) {
              this.log += 'getSavedFileListTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("getSavedFileListTest success", res)
            this.fileListSuccess = res.fileList
            this.getSavedFileListRet = "getSavedFileList:ok"
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'getSavedFileListTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('getSavedFileListTest fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

            this.getSavedFileListRet = JSON.stringify(res)
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            } else {
              this.fileListComplete = (res as GetSavedFileListResult).fileList
            }
          }
        } as GetSavedFileListOptions)
      },
      truncateFileTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.truncate({
          filePath: `${this.basePath}${this.writeFile}`,
          length: 6,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'truncateFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'truncateFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as TruncateFileOptions)
      },
      truncateFileSyncTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.truncateSync(
            `${this.basePath}${this.writeFile}`,
            3)
          this.done = true
        } catch (e) {
          console.log(e)
          this.done = true
        }
      },
      readCompressedFileTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.readCompressedFile({
          filePath: '/static/filemanager/1.txt.br',
          compressionAlgorithm: "br",
          success: (res : ReadCompressedFileResult) => {
            if (this.logAble) {
              this.log += 'readCompressedFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'readCompressedFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (_) => {
            this.done = true
          }
        } as ReadCompressedFileOptions)
      },
      readCompressedFileSyncTest() {
        console.log('readCompressedFileSyncTest')
        const fileManager = uni.getFileSystemManager()
        try {
          let data = fileManager.readCompressedFileSync(
            '/static/filemanager/1.txt.br',
            "br")
          if (this.logAble) {
            this.log += data
          }
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'readCompressedFileSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }

      },
      removeSavedFileTest() {
        console.log("removeSavedFileTest enter")
        const fileManager = uni.getFileSystemManager()
        fileManager.removeSavedFile({
          filePath: `${this.basePath}${this.writeFile}`,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'removeSavedFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            this.removeSavedFileRet = res.errMsg
            console.log("removeSavedFileTest success", res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'removeSavedFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('removeSavedFileTest fail', res)
          },
          complete: (_) => {
            this.done = true
          }
        } as RemoveSavedFileOptions)
      },

      statFileInfoSyncTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        try {
          let res = fileManager.statSync(
            // path: `${this.basePath}${this.statFile}`, //USER_DATA_PATH
            `${this.globalTempPath}${this.statFile}`, //CACHE_PATH
            this.recursiveVal)
          if (this.logAble) {
            this.log += 'statFileInfoSyncTest success:' + JSON.stringify(res) + '\n\n'
          }
          this.statsRet = res
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'statFileInfoSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }

      },
      openFileTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.open({
          filePath: `${this.basePath}${this.readFile}`,
          flag: "a",
          success: (res : OpenFileSuccessResult) => {
            if (this.logAble) {
              this.log += 'openFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
            this.fd = res.fd
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (_) => {
            this.done = true
          }
        } as OpenFileOptions)
      },
      openFileSyncTest(param : string, isTest : boolean) : string {
        const fileManager = uni.getFileSystemManager()
        try {
          let fd = fileManager.openSync({
            filePath: `${this.basePath}${this.readFile}`,
            flag: param,
          } as OpenFileSyncOptions)
          if (this.logAble && isTest) {
            this.log += 'openFileSyncTest success:' + fd + '\n\n'
          }
          if (isTest) {
            this.done = true
          }

          this.fd = fd
          return fd
        } catch (e) {
          if (this.logAble) {
            this.log += 'openFileSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          console.log('fail', e)
          this.done = true
        }
        return ""
      },
      closeSyncTest() {
        console.log('closeSyncTest')
        const fileManager = uni.getFileSystemManager()
        try {
          console.log('closeSync')
          fileManager.closeSync({
            fd: this.openFileSyncTest('r', false)
          } as CloseSyncOptions)
          if (this.logAble) {
            this.log += 'closeSyncTest success:' + '\n\n'
          }
          this.done = true
          this.closeFileRet = "close:ok"
        } catch (e) {
          if (this.logAble) {
            this.log += 'closeSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          console.log('fail', e)
          this.done = true
        }
      },
      closeTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.close({
          fd: this.openFileSyncTest('r', false),
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'closeTest success:' + JSON.stringify(res) + '\n\n'
            }
            this.closeFileRet = res.errMsg
            console.log("success", res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'closeTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (_) => {
            this.done = true
          }

        } as CloseOptions)
      },
      writeTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, true)
        } catch (e) {
          console.error(e)
        }

        fileManager.write({
          fd: this.openFileSyncTest('w+', false),
          data: this.writeData,
          encoding: "utf-8",
          success: (res : WriteResult) => {
            if (this.logAble) {
              this.log += 'writeTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
            this.bytesWritten = res.bytesWritten
            this.lastFailError = new UniError('uni-fileSystemManager', 0, 'writeTest success:' + JSON.stringify(res))
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'writeTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, 'writeTest:' + res.errMsg)

          },
          complete: (_) => {
            this.done = true
          }

        } as WriteOptions)
      },
      writeSyncTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, true)
        } catch (e) {
          console.error(e)
        }
        fileManager.open({
          filePath: `${this.basePath}${this.readFile}`,
          flag: "r+",
          success: (res : OpenFileSuccessResult) => {
            console.log("success", res)
            if (res.fd.length <= 0) {
              this.done = true
              return
            }
            try {
              let ret = fileManager.writeSync({
                fd: res.fd,
                data: this.writeData,
                encoding: "utf-8"
              } as WriteSyncOptions)
              if (this.logAble) {
                this.log += 'writeSyncTest success:' + JSON.stringify(ret) + '\n\n'
              }
              console.log("success", ret)
              this.done = true
              this.bytesWritten = ret.bytesWritten
            } catch (e) {
              if (this.logAble) {
                this.log += 'writeSyncTest fail:' + JSON.stringify(e) + '\n\n'
              }
              console.log('fail', e)
              this.done = true
            }
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

            this.done = true
          }
        } as OpenFileOptions)

      },
      fstatTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.fstat({
          fd: this.openFileSyncTest('r', false),
          success: (res : FStatSuccessResult) => {
            if (this.logAble) {
              this.log += 'fstatTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
            this.fstat = res.stats
            this.fstatSize = res.stats.size
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'fstatTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (_) => {
            this.done = true
          }

        } as FStatOptions)
      },
      fstatSyncTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          let stat =
            fileManager.fstatSync({
              fd: this.openFileSyncTest('r', false),
            } as FStatSyncOptions)
          if (this.logAble) {
            this.log += 'fstatSyncTest success:' + JSON.stringify(stat) + '\n\n'
          }
          this.done = true
          this.fstat = stat
          this.fstatSize = stat.size
        } catch (e) {
          if (this.logAble) {
            this.log += 'fstatSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          this.done = true
        }
      },
      ftruncateFileTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.ftruncate({
          fd: this.openFileSyncTest('r+', false),
          length: 6,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'ftruncateFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            this.ftruncateRet = res.errMsg
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'ftruncateFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as FTruncateFileOptions)
      },
      ftruncateFileSyncTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.ftruncateSync({
            fd: this.openFileSyncTest('r+', false),
            length: 4
          } as FTruncateFileSyncOptions)
          if (this.logAble) {
            this.log += 'ftruncateFileSyncTest success:' + '\n\n'
          }
          this.done = true
          this.ftruncateRet = 'ftruncate:ok'
        } catch (e) {
          if (this.logAble) {
            this.log += 'ftruncateFileSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          this.done = true
        }
      },
      readZipEntry() {
        const fileManager = uni.getFileSystemManager()
        fileManager.readZipEntry({
          filePath: '/static/filemanager/to.zip',
          encoding: 'utf-8',
          success: (res : EntriesResult) => {
            if (this.logAble) {
              this.log += 'readZipEntry success:size=' + res.result + '\n\n'
            }
            console.log("success", res)
          },
          fail: (res : IUniError) => {
            if (this.logAble) {
              this.log += 'readZipEntry fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

          }
        } as ReadZipEntryOptions)
      },
      testWriteReadFileBuffer() {
        const fs = uni.getFileSystemManager()
        let buffer = new ArrayBuffer(16)
        let float64 = new Float64Array(buffer)
        float64[1] = 1.2222222
        let that = this
        fs.writeFile({
          filePath: `${uni.env.USER_DATA_PATH}/hello.txt`,
          // data: 'test some',
          data: buffer,
          // encoding: 'ascii',
          success: (res) => {
            if (this.logAble) {
              this.log += 'testWriteReadFileBuffer :' + res.errMsg + '\n\n'
            }
            console.log(res)
            // that.testAppendFile()
            that.testReadFileBuffer()
          },
          fail: (res) => {
            if (this.logAble) {
              this.log += 'testWriteReadFileBuffer fail:' + JSON.stringify(res) + '\n\n'
            }
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)

            console.error(res)
            this.done = true
          },
          complete: (_ : any) => {

          }
        } as WriteFileOptions)
      },
      testReadFileBuffer() {
        const fs = uni.getFileSystemManager()
        fs.readFile({
          filePath: `${uni.env.USER_DATA_PATH}/hello.txt`,

          success: (res) => {

            console.log(res)
            // let uint8Array = new Uint8Array(res.data as ArrayBuffer)
            // for (let i = 0; i < uint8Array.length; i++) {
            // 	console.log(`Byte ${i}: ${uint8Array[i]}`);
            // }
            let float64 = new Float64Array(res.data as ArrayBuffer)
            if (this.logAble) {
              for (let i = 0; i < float64.length; i++) {
                if (this.logAble) {
                  this.log += 'testReadFileBuffer success :' + `Byte ${i}: ${float64[i]}` + '\n\n'
                }
              }
            }
            this.arrayBufferRes = float64[1] //1.2222222
            console.log(this.arrayBufferRes)
          },
          fail: (res) => {
            if (this.logAble) {
              this.log += 'testReadFileBuffer fail:' + JSON.stringify(res) + '\n\n'
            }
            this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)
            console.error(res)
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as ReadFileOptions)
      },
      testWriteReadFileSyncBuffer() {
        try {
          const fs = uni.getFileSystemManager()
          let buffer = new ArrayBuffer(16)
          // let int8 = new Int8Array(buffer)
          // int8[1] = 20
          let float64 = new Float64Array(buffer)
          float64[1] = 1.333
          fs.writeFileSync(`${uni.env.USER_DATA_PATH}/hello.txt`, buffer, 'utf-8')
          if (this.logAble) {
            this.log += 'testWriteReadFileSyncBuffer success' + '\n\n'
          }
          this.testReadFileSyncBuffer()
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'testWriteReadFileSyncBuffer fail:' + JSON.stringify(e) + '\n\n'
          }
          this.done = true
        }

      },
      testReadFileSyncBuffer() {
        try {
          const fs = uni.getFileSystemManager()
          let res = fs.readFileSync(`${uni.env.USER_DATA_PATH}/hello.txt`, null)
          console.log(res)
          let float64 = new Float64Array(res as ArrayBuffer)
          for (let i = 0; i < float64.length; i++) {
            if (this.logAble) {
              this.log += 'testReadFileSyncBuffer success:' + `Byte ${i}: ${float64[i]}` + '\n\n'
            }
            console.log(`Byte ${i}: ${float64[i]}`);
          }
          this.arrayBufferRes = float64[1] // 1.333
          console.log(this.arrayBufferRes)
        } catch (e) {
          if (this.logAble) {
            this.log += 'testReadFileSyncBuffer fail:' + JSON.stringify(e) + '\n\n'
          }
          this.done = true
        }

      },

      testWriteReadBuffer() {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, true)
        } catch (e) {
          console.error(e)
        }

        let buffer = new ArrayBuffer(24)
        let float64 = new Float64Array(buffer)
        float64[1] = 1.24
        float64[2] = 1.33

        fileManager.write({
          fd: this.openFileSyncTest('w+', false),
          length: 16,
          offset: 8,
          data: buffer,
          position: 10,
          success: (res : WriteResult) => {
            console.log("success", res)

            const ab = new ArrayBuffer(24)
            fileManager.read({
              arrayBuffer: ab,
              fd: this.openFileSyncTest('a+', false),
              length: 8,
              position: 10,
              success: (res : ReadSuccessCallbackResult) => {
                console.log(res)
                let value = new Float64Array(res.arrayBuffer)
                for (let i = 0; i < value.length; i++) {
                  console.log(`Byte ${i}: ${value[i]}`);
                  if (this.logAble) {
                    this.log += 'testWriteReadBuffer success:' + `Byte ${i}: ${value[i]}` + '\n\n'
                  }
                }
                this.arrayBufferRes = value[0] //1.24
                console.log(this.arrayBufferRes)
              },
              fail: (res) => {
                console.log(res)
                this.done = true
                if (res instanceof UniError) {
                  this.lastCompleteError = res
                }
              },
              complete: (res : any) => {
                console.log("complete", res)
                this.done = true
                if (res instanceof UniError) {
                  this.lastCompleteError = res
                }
              }
            } as ReadOption)
          },
          fail: (res : IUniError) => {
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          },
          complete: (_) => {

          }

        } as WriteOptions)
      },
      testWriteReadSyncBuffer() {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, true)
        } catch (e) {
        }
        try {

          let buffer = new ArrayBuffer(24)
          let float64 = new Float64Array(buffer)
          float64[1] = 1.11
          float64[2] = 1.33
          let ret = fileManager.writeSync({
            fd: this.openFileSyncTest('w+', false),
            // data: this.writeData,
            data: buffer,
            length: 16,
            offset: 8,
            position: 10,
            encoding: "utf-8"
          } as WriteSyncOptions)
          console.log("success", ret)

          const ab = new ArrayBuffer(24)
          let res = fileManager.readSync({
            arrayBuffer: ab,
            fd: this.openFileSyncTest('a+', false),
            length: 8,
            offset: 8,
            position: 10
          } as ReadSyncOption)
          console.log(res)
          let value = new Float64Array(res.arrayBuffer)
          for (let i = 0; i < value.length; i++) {
            if (this.logAble) {
              this.log += 'testWriteReadSyncBuffer success :' + `Byte ${i}: ${value[i]}` + '\n\n'
            }
          }
          this.done = true
          this.arrayBufferRes = float64[1] //1.11
          console.log(this.arrayBufferRes)
        } catch (e) {
          this.done = true
          console.error(e)
        }
      },


      testAppendFileBufferSync() {
        // 同步接口
        const fs = uni.getFileSystemManager()
        try {
          let buffer = new ArrayBuffer(24)
          let float64 = new Float64Array(buffer)
          float64[1] = 1.2222222
          float64[2] = 1.33
          let ret = fs.writeSync({
            fd: fs.openSync({ filePath: `${uni.env.USER_DATA_PATH}/hello.txt`, flag: 'w+' } as OpenFileSyncOptions),
            data: buffer,
            length: 16,
            offset: 8,
            position: 10
          } as WriteSyncOptions)
          console.log(ret)


          buffer = new ArrayBuffer(16)
          float64 = new Float64Array(buffer)
          float64[0] = 20
          fs.appendFileSync(`${uni.env.USER_DATA_PATH}/hello.txt`, buffer, null)
          const ab = new ArrayBuffer(32)
          // 打开文件
          // 读取文件到 ArrayBuffer 中
          let readResult = fs.readSync({
            fd: fs.openSync({
              filePath: `${uni.env.USER_DATA_PATH}/hello.txt`,
              flag: 'a+',
            } as OpenFileSyncOptions),
            arrayBuffer: ab,
            length: 24,
            position: 10,
            offset: 8
          } as ReadSyncOption)
          console.log(readResult)
          float64 = new Float64Array(readResult.arrayBuffer)

          for (let i = 0; i < float64.length; i++) {
            if (this.logAble) {
              this.log += 'testAppendFileBufferSync success :' + `Byte ${i}: ${float64[i]}` + '\n\n'
            }
            console.log(`Byte ${i}: ${float64[i]}`);
          }
          this.arrayBufferRes = float64[3] //20
          console.log(this.arrayBufferRes)
          this.done = true
        } catch (e) {
          this.done = true
          if (this.logAble) {
            this.log += 'testAppendFileBufferSync fail:' + JSON.stringify(e) + '\n\n'
          }
          console.error(e)
        }
      },

      testAppendFileBuffer() {
        // 同步接口
        const fs = uni.getFileSystemManager()
        try {
          let buffer = new ArrayBuffer(24)
          let float64 = new Float64Array(buffer)
          float64[1] = 1.2222222
          float64[2] = 1.33
          let ret = fs.writeSync({
            fd: fs.openSync({ filePath: `${uni.env.USER_DATA_PATH}/hello.txt`, flag: 'w+' } as OpenFileSyncOptions),
            data: buffer,
            length: 16,
            offset: 8,
            position: 10
          } as WriteSyncOptions)
          console.log(ret)

          buffer = new ArrayBuffer(16)
          float64 = new Float64Array(buffer)
          float64[0] = 21
          fs.appendFile({
            filePath: `${uni.env.USER_DATA_PATH}/hello.txt`,
            data: buffer,
            success: (res) => {
              console.log(res)
              const ab = new ArrayBuffer(32)
              // 打开文件
              // 读取文件到 ArrayBuffer 中
              let readResult = fs.readSync({
                fd: fs.openSync({
                  filePath: `${uni.env.USER_DATA_PATH}/hello.txt`,
                  flag: 'a+',
                } as OpenFileSyncOptions),
                arrayBuffer: ab,
                length: 24,
                position: 10,
                offset: 8
              } as ReadSyncOption)
              console.log(readResult)
              float64 = new Float64Array(readResult.arrayBuffer)

              for (let i = 0; i < float64.length; i++) {
                console.log(`Byte ${i}: ${float64[i]}`);
                if (this.logAble) {
                  this.log += 'testAppendFileBuffer success :' + `Byte ${i}: ${float64[i]}` + '\n\n'
                }
              }
              this.arrayBufferRes = float64[3] //21
              console.log(this.arrayBufferRes)
            },
            fail: (res) => {
              console.log(res)
            },
            complete: (_) => {
              this.done = true
            }
          } as AppendFileOptions)

        } catch (e) {
          this.done = true
          if (this.logAble) {
            this.log += 'testAppendFileBufferSync fail:' + JSON.stringify(e) + '\n\n'
          }
          console.error(e)
        }
      },
      // #ifdef APP
      testReadFileEncoding(encoding : string) {
        console.log('testEncoding', encoding)
        uni.chooseImage({
          count: 1,
          albumMode: "system",
          sizeType: ["original"],
          sourceType: ["album"],
          success: (e) => {
            console.log(e.tempFilePaths[0])
            uni.getFileSystemManager().readFile({
              filePath: e.tempFilePaths[0],
              encoding: encoding,
              success: (res) => {
                console.log('success:', (res.data as string).length)
              }
            })
          }
        })
      },
      testReadFileArrayBuffer() {
        uni.chooseImage({
          count: 1,
          albumMode: "system",
          sizeType: ["original"],
          sourceType: ["album"],
          success: (e) => {
            console.log(e.tempFilePaths[0])
            uni.getFileSystemManager().readFile({
              filePath: e.tempFilePaths[0],
              success: (res) => {
                console.log('success:', (res.data as ArrayBuffer).byteLength)
              }
            })
          }
        })
      },
      testReadFileSyncEncoding(encoding : string) {
        console.log('testEncoding', encoding)
        uni.chooseImage({
          count: 1,
          albumMode: "system",
          sizeType: ["original"],
          sourceType: ["album"],
          success: (e) => {
            console.log(e.tempFilePaths[0])
            try {
              let res = uni.getFileSystemManager().readFileSync(e.tempFilePaths[0], encoding)
              console.log('success:', (res as string).length)
            } catch (e) {
              console.log(e)
            }
          }
        })
      },
      testReadFileSyncArrayBuffer() {
        uni.chooseImage({
          count: 1,
          albumMode: "system",
          sizeType: ["original"],
          sourceType: ["album"],
          success: (e) => {
            console.log(e.tempFilePaths[0])
            try {
              let res = uni.getFileSystemManager().readFileSync(e.tempFilePaths[0], null)
              console.log('success:', (res as ArrayBuffer).byteLength)
            } catch (e) {
              console.log(e)
            }
          }
        })
      },
      copyFileByContent() {
        uni.chooseImage({
          count: 1,
          albumMode: "system",
          sizeType: ["original"],
          sourceType: ["album"],
          success: (e) => {
            console.log(e.tempFilePaths[0])
            uni.getFileSystemManager().copyFile({
              srcPath: e.tempFilePaths[0],
              destPath: uni.env.CACHE_PATH + 'copyFileByContent.jpg',
              complete: (res) => {
                console.log('success:', res)
              }
            })
          }
        })
      },
      copyFileSyncByContent() {
        uni.chooseImage({
          count: 1,
          albumMode: "system",
          sizeType: ["original"],
          sourceType: ["album"],
          success: (e) => {
            console.log(e.tempFilePaths[0])
            try {
              let res = uni.getFileSystemManager().copyFileSync(e.tempFilePaths[0], uni.env.CACHE_PATH + 'copyFileSyncByContent.jpg',)
              console.log('success:', res)
            } catch (e) {
              console.log(e)
            }
          }
        })
      },
      // #endif
    },


  }
</script>

<style>
  .btnstyle {
    margin: 4px;
  }
</style>

# 通用类型

# GeneralCallbackResult

名称 类型 必备 默认值 兼容性 描述
errMsg string -
错误信息
本页导读