抖音开放平台Logo
控制台

tt.inflate

更新时间 2024-08-15 03:22:51
收藏
我的收藏

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

提供解压缩的能力,支持由 zlib.deflateSynczlib.deflateRawSync 得到的压缩数据。与 node 提供的异步解压缩方法不同,这是一个同步方法。

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

语法

tt.inflate(buffer, raw)

参数说明

buffer

类型默认值必填说明最低支持版本
arrayBuffer

可以通过 tt.createBuffer() 提供的 from 方法得到

1.3.0

raw

类型默认值必填说明最低支持版本
booleanfalse

当参数 raw 为 false 时,对应的压缩方法为 zlib.deflateSync,对应的解压缩方法为 zlib.inflateSync,与 zlib 提供的异步解压缩方法不同,小游戏中提供的 tt.inflate 是同步的。
当参数 raw 为 true 时,对应的压缩方法为
zlib.deflateRawSync,对应的解压缩方法为 zlib.inflateRawSync ,与 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