- API 概览
- 开放能力
- 基础
- 渲染
- 设备
- 文件
- 位置
- 媒体
- 网络
- 游戏转发分享
- 实时语音
- 数据缓存
- 系统
- 广告
- 界面
- 支付
- Worker
tt.inflate
更新时间 2024-08-15 03:22:51
收藏
我的收藏基础库 1.3.0 开始支持本方法,这是一个同步方法。
提供解压缩的能力,支持由 zlib.deflateSync 和 zlib.deflateRawSync 得到的压缩数据。与 node 提供的异步解压缩方法不同,这是一个同步方法。
前提条件 | 无 |
业务背景 | 无 |
使用限制 | 无 |
注意事项 | 无 |
相关教程 | 无 |
语法
tt.inflate(buffer, raw)
参数说明
buffer
类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|
arrayBuffer | 是 | 可以通过 tt.createBuffer() 提供的 from 方法得到 | 1.3.0 |
raw
类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|
boolean | false | 否 | 当参数 raw 为 false 时,对应的压缩方法为 zlib.deflateSync,对应的解压缩方法为 zlib.inflateSync,与 zlib 提供的异步解压缩方法不同,小游戏中提供的 tt.inflate 是同步的。 | 1.98.0 |
返回值
类型 | 说明 | 最低支持版本 |
---|---|---|
arrayBuffer | Uint8Array。可以通过 tt.createBuffer() 提供的 toString 方法将结果转化为字符串 | 1.3.0 |
扫码体验
请使用字节宿主APP扫码
代码示例
const Buffer = tt.createBuffer();
const content1 = "eJxzT03NLgYABXQB8A==";
const buffer1 = Buffer.from(content1, "base64");
const result1 = tt.inflate(buffer1); // 默认为false
console.log(
`[API: ZLIB] the result of inflate is: ${Buffer.toString(result1)}`
);
// [API: ZLIB] the result of inflate is: Geeks
const content2 = "c09NzS4GAA==";
const buffer2 = Buffer.from(content2, "base64");
const result2 = tt.inflate(buffer2, true);
console.log(
`[API: ZLIB] the result of inflate raw is: ${Buffer.toString(result2)}`
);
// [API: ZLIB] the result of inflate raw is: Geeks
该文档是否有帮助?
点击纠错