抖音开放平台Logo
开发者文档
“/”唤起搜索
控制台

FileSystemManager.readZipEntry

收藏
我的收藏

基础库 2.90.0 开始支持本方法,这是一个异步方法。

读取压缩包内的文件。

前提条件
业务背景
使用限制
注意事项
相关教程

语法

FileSystemManager.readZipEntry(options)

参数说明

options 为 object 类型,属性如下:

属性名类型默认值必填说明最低支持版本
encodingenum
统一指定读取文件的字符编码,只在 entries 值为"all"时有效。如果 entries 值为"all"且不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容
2.90.0
filePathstring
要读取的压缩包的路径 (本地路径)
2.90.0
entriesArray<object>
要读取的压缩包内的文件列表(当传入"all" 时表示读取压缩包内所有文件)
2.90.0
successfunction
接口调用成功的回调函数
2.90.0
failfunction
接口调用失败的回调函数
2.90.0
completefunction
接口调用结束的回调函数(调用成功、失败都会执行)
2.90.0

entries 参数说明

Array<object> | 'all' 类型,传入 object 时属性如下:

属性名

类型

默认值

必填

说明

path

string


压缩包内文件路径,entries中对象之间的path不可重复

encoding

string


指定读取文件的字符编码,如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容

encoding 的合法值

说明最低支持版本
ascii
-
2.90.0
base64
-
2.90.0
binary
-
2.90.0
hex
-
2.90.0
ucs2
以小端序读取
2.90.0
ucs-2
以小端序读取
2.90.0
utf16le
以小端序读取
2.90.0
utf-16le
以小端序读取
2.90.0
utf-8
-
2.90.0
utf8
-
2.90.0
latin1
-
2.90.0

回调成功

object 类型,属性如下:

属性名类型说明最低支持版本
entriesobject
文件读取结果。entries 是一个对象,key是文件路径,value是一个对象 FileItem ,表示该文件的读取结果。每个 FileItem 包含 data (文件内容) 和 errMsg (错误信息) 属性。
2.90.0
errMsgstring
"FileSystemManager.readZipEntry:ok"
2.90.0

entries 参数说明

object 类型,属性如下:

属性名

类型

说明

最低支持版本

path


FileItem: { data: string/ArrayBuffer, errMsg: string, }


文件路径

2.90.0

回调失败

object 类型,属性如下:

属性名类型说明最低支持版本
errMsgstring
"FileSystemManager.readZipEntry:fail" + 详细错误信息
2.90.0

错误码

errNoerrMsg说明最低支持版本
20001invalid param
参数错误
2.90.0
10401error stack
小游戏框架内部错误,有需要请创建工单咨询
2.90.0
21101permission denied, $apiName $dirPath
2.90.0
21102no such file or directory, $apiName $dirPath
2.90.0
21103operation not permitted, $apiName $filePath
2.90.0
21106unzip open file fail
小游戏框架内部错误,有需要请创建工单咨询
2.90.0
20001option.entries.path should not be repeated
entries中对象之间的path不可重复
2.90.0
21103no such file or directory, $apiName $filePath
2.90.0
21102operation not permitted, $apiName $filePath
2.90.0
20000internal error
小游戏框架内部错误,有需要请创建工单咨询
2.90.0

代码示例

const fs = tt.getFileSystemManager(); // 读取压缩包内所有文件 fs.readZipEntry({ filePath: "zipPath", entries: "all", encoding: "utf8", success(res) { console.log("读取压缩包内所有文件成功", res); }, fail(res) { console.log("读取压缩包内所有文件失败", res); }, }); // 读取压缩包内指定文件 fs.readZipEntry({ filePath: "zipPath", entries: [ { path: "zipEntryPath1", }, { path: "zipEntryPath2", encoding: "utf8", }, ], success(res) { console.log("读取指定压缩文件成功", res); }, fail(res) { console.log("读取指定压缩文件失败", res); }, }); const fs = tt.getFileSystemManager(); // 读取压缩包内所有文件 fs.readZipEntry({ filePath: "zipPath", entries: "all", encoding: "utf8", success(res) { console.log("读取压缩包内所有文件成功", res); }, fail(res) { console.log("读取压缩包内所有文件失败", res); }, }); // 读取压缩包内指定文件 fs.readZipEntry({ filePath: "zipPath", entries: [ { path: "zipEntryPath1", }, { path: "zipEntryPath2", encoding: "utf8", }, ], success(res) { console.log("读取指定压缩文件成功", res); }, fail(res) { console.log("读取指定压缩文件失败", res); }, });