1e41f4b71Sopenharmony_ci# @ohos.zlib (Zip模块)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci本模块提供压缩解压缩文件的能力。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## 导入模块
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```javascript
12e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
13e41f4b71Sopenharmony_ci```
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## zlib.zipFile<sup>(deprecated)</sup>
16e41f4b71Sopenharmony_cizipFile(inFile: string, outFile: string, options: Options): Promise&lt;void&gt;
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci压缩接口,压缩完成后返回执行结果,使用Promise异步返回。
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci> **说明:**
21e41f4b71Sopenharmony_ci>
22e41f4b71Sopenharmony_ci> 从API version 7 开始支持,从API 9 开始废弃。建议使用[zlib.compressFile](#zlibcompressfile9)。
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**参数:**
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci| 参数名  | 类型                | 必填 | 说明                                                         |
29e41f4b71Sopenharmony_ci| ------- | ------------------- | ---- | ------------------------------------------------------------ |
30e41f4b71Sopenharmony_ci| inFile  | string              | 是   | 指定压缩的文件夹路径或者文件路径,路径必须为沙箱路径,沙箱路径可以通过context获取,可参考[FA模型](../apis-ability-kit/js-apis-inner-app-context.md),[Stage模型](../apis-ability-kit/js-apis-inner-application-context.md)。 |
31e41f4b71Sopenharmony_ci| outFile | string              | 是   | 指定压缩结果的文件路径(文件的扩展名zip)。                  |
32e41f4b71Sopenharmony_ci| options | [Options](#options) | 是   | 压缩的可选参数。                                             |
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci**返回值:**
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci| 类型           | 说明                                                         |
37e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ |
38e41f4b71Sopenharmony_ci| Promise\<void> | Promise对象,无返回值。 |
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**示例:**
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci```ts
43e41f4b71Sopenharmony_ci// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/haps,也可以通过context获取。
44e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_cilet inFile = '/xxx/filename.xxx';
47e41f4b71Sopenharmony_cilet outFile = '/xxx/xxx.zip';
48e41f4b71Sopenharmony_cilet options: zlib.Options = {
49e41f4b71Sopenharmony_ci  level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
50e41f4b71Sopenharmony_ci  memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
51e41f4b71Sopenharmony_ci  strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
52e41f4b71Sopenharmony_ci};
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_cizlib.zipFile(inFile, outFile, options).then((data: void) => {
55e41f4b71Sopenharmony_ci  console.info('zipFile result is ' + JSON.stringify(data));
56e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
57e41f4b71Sopenharmony_ci  console.error('error is ' + JSON.stringify(err));
58e41f4b71Sopenharmony_ci});
59e41f4b71Sopenharmony_ci```
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci## zlib.unzipFile<sup>(deprecated)</sup>
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ciunzipFile(inFile:string, outFile:string, options: Options): Promise&lt;void&gt;
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci解压文件,解压完成后返回执行结果,使用Promise异步返回。
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci> **说明:**
68e41f4b71Sopenharmony_ci>
69e41f4b71Sopenharmony_ci> 从API version 7 开始支持,从API 9 开始废弃。建议使用[zlib.decompressFile](#zlibdecompressfile9)。
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci**参数:**
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci| 参数名  | 类型                | 必填 | 说明                                                         |
76e41f4b71Sopenharmony_ci| ------- | ------------------- | ---- | ------------------------------------------------------------ |
77e41f4b71Sopenharmony_ci| inFile  | string              | 是   | 指定的待解压缩文件的文件路径,路径必须为沙箱路径,沙箱路径可以通过context获取,可参考[FA模型](../apis-ability-kit/js-apis-inner-app-context.md),[Stage模型](../apis-ability-kit/js-apis-inner-application-context.md)。 |
78e41f4b71Sopenharmony_ci| outFile | string              | 是   | 指定的解压文件路径。                                         |
79e41f4b71Sopenharmony_ci| options | [Options](#options) | 是   | 解压的可选参数。                                             |
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci**返回值:**
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci| 类型           | 说明                                                         |
84e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ |
85e41f4b71Sopenharmony_ci| Promise\<void> | Promise对象,无返回值。 |
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci**示例:**
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci```ts
90e41f4b71Sopenharmony_ci// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/haps,也可以通过context获取。
91e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_cilet inFile = '/xx/xxx.zip';
94e41f4b71Sopenharmony_cilet outFile = '/xxx';
95e41f4b71Sopenharmony_cilet options: zlib.Options = {
96e41f4b71Sopenharmony_ci  level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
97e41f4b71Sopenharmony_ci  memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
98e41f4b71Sopenharmony_ci  strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
99e41f4b71Sopenharmony_ci};
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_cizlib.unzipFile(inFile, outFile, options).then((data: void) => {
102e41f4b71Sopenharmony_ci  console.info('unzipFile result is ' + JSON.stringify(data));
103e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
104e41f4b71Sopenharmony_ci  console.error('error is ' + JSON.stringify(err));
105e41f4b71Sopenharmony_ci})
106e41f4b71Sopenharmony_ci```
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci## zlib.compressFile<sup>9+</sup>
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_cicompressFile(inFile: string, outFile: string, options: Options, callback: AsyncCallback\<void>): void
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci压缩文件,压缩的结果,使用callback异步回调返回。成功返回null,失败返回错误码。
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci> **说明:**
115e41f4b71Sopenharmony_ci>
116e41f4b71Sopenharmony_ci>为了避免路径穿越,从API version 13开始,inFile和outFile传入的参数不允许包含../,否则会返回900001、900002错误码。
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci**参数:**
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci| 参数名                  | 类型                | 必填 | 说明                                                         |
125e41f4b71Sopenharmony_ci| ----------------------- | ------------------- | ---- | ------------------------------------------------------------ |
126e41f4b71Sopenharmony_ci| inFile                  | string              | 是   | 指定压缩的文件夹路径或者文件路径,路径必须为沙箱路径,沙箱路径可以通过context获取,可参考[FA模型](../apis-ability-kit/js-apis-inner-app-context.md),[Stage模型](../apis-ability-kit/js-apis-inner-application-context.md)。待压缩的文件夹不可为空,否则使用[decompressFile](#zlibdecompressfile9)对压缩后的文件解压时会报错。 |
127e41f4b71Sopenharmony_ci| outFile                 | string              | 是   | 指定的压缩结果的文件路径。多个线程同时压缩文件时,outFile不能相同。                                           |
128e41f4b71Sopenharmony_ci| options                 | [Options](#options) | 是   | 压缩的配置参数。                                               |
129e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>            | 是   | 异步获取压缩结果之后的回调。成功返回null,失败返回错误码。             |
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci**错误码:**
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                               |
136e41f4b71Sopenharmony_ci| -------- | --------------------------------------|
137e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
138e41f4b71Sopenharmony_ci| 900001   | The input source file is invalid.      |
139e41f4b71Sopenharmony_ci| 900002   | The input destination file is invalid. |
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci**示例:**
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci```ts
144e41f4b71Sopenharmony_ci// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/haps,也可以通过context获取。
145e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_cilet inFile = '/xxx/filename.xxx';
148e41f4b71Sopenharmony_cilet outFile = '/xxx/xxx.zip';
149e41f4b71Sopenharmony_cilet options: zlib.Options = {
150e41f4b71Sopenharmony_ci  level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
151e41f4b71Sopenharmony_ci  memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
152e41f4b71Sopenharmony_ci  strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
153e41f4b71Sopenharmony_ci};
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_citry {
156e41f4b71Sopenharmony_ci  zlib.compressFile(inFile, outFile, options, (errData: BusinessError) => {
157e41f4b71Sopenharmony_ci    if (errData !== null) {
158e41f4b71Sopenharmony_ci      console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
159e41f4b71Sopenharmony_ci    }
160e41f4b71Sopenharmony_ci  })
161e41f4b71Sopenharmony_ci} catch (errData) {
162e41f4b71Sopenharmony_ci  let code = (errData as BusinessError).code;
163e41f4b71Sopenharmony_ci  let message = (errData as BusinessError).message;
164e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${code}  message:${message}`);
165e41f4b71Sopenharmony_ci}
166e41f4b71Sopenharmony_ci```
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci## zlib.compressFile<sup>9+</sup>
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_cicompressFile(inFile: string, outFile: string, options: Options): Promise\<void>
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci压缩文件,压缩的结果,使用Promise异步返回。成功时返回null,失败时返回错误码。
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci> **说明:**
175e41f4b71Sopenharmony_ci>
176e41f4b71Sopenharmony_ci>为了避免路径穿越,从API version 13开始,inFile和outFile传入的参数不允许包含../,否则会返回900001、900002错误码。
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci**参数:**
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci| 参数名  | 类型                | 必填 | 说明                                                         |
185e41f4b71Sopenharmony_ci| ------- | ------------------- | ---- | ------------------------------------------------------------ |
186e41f4b71Sopenharmony_ci| inFile  | string              | 是   | 指定压缩的文件夹路径或者文件路径,路径必须为沙箱路径,沙箱路径可以通过context获取,可参考[FA模型](../apis-ability-kit/js-apis-inner-app-context.md),[Stage模型](../apis-ability-kit/js-apis-inner-application-context.md)。待压缩的文件夹不可为空,否则使用[decompressFile](#zlibdecompressfile9)对压缩后的文件解压时会报错。 |
187e41f4b71Sopenharmony_ci| outFile | string              | 是   | 指定的压缩结果的文件路径。多个线程同时压缩文件时,outFile不能相同。                                           |
188e41f4b71Sopenharmony_ci| options | [Options](#options) | 是   | 压缩的配置参数。                                               |
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci**返回值:**
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci| 类型           | 说明                    |
193e41f4b71Sopenharmony_ci| -------------- | ----------------------- |
194e41f4b71Sopenharmony_ci| Promise\<void> | Promise对象,无返回值。 |
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci**错误码:**
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                               |
201e41f4b71Sopenharmony_ci| -------- | ------------------------------------- |
202e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
203e41f4b71Sopenharmony_ci| 900001   | The input source file is invalid.      |
204e41f4b71Sopenharmony_ci| 900002   | The input destination file is invalid. |
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ci**示例:**
207e41f4b71Sopenharmony_ci
208e41f4b71Sopenharmony_ci```ts
209e41f4b71Sopenharmony_ci// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/haps,也可以通过context获取。
210e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_cilet inFile = '/xxx/filename.xxx';
213e41f4b71Sopenharmony_cilet outFile = '/xxx/xxx.zip';
214e41f4b71Sopenharmony_cilet options: zlib.Options = {
215e41f4b71Sopenharmony_ci  level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
216e41f4b71Sopenharmony_ci  memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
217e41f4b71Sopenharmony_ci  strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
218e41f4b71Sopenharmony_ci};
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_citry {
221e41f4b71Sopenharmony_ci  zlib.compressFile(inFile, outFile, options).then((data: void) => {
222e41f4b71Sopenharmony_ci    console.info('compressFile success. data: ' + JSON.stringify(data));
223e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
224e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
225e41f4b71Sopenharmony_ci  })
226e41f4b71Sopenharmony_ci} catch (errData) {
227e41f4b71Sopenharmony_ci  let code = (errData as BusinessError).code;
228e41f4b71Sopenharmony_ci  let message = (errData as BusinessError).message;
229e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${code}  message:${message}`);
230e41f4b71Sopenharmony_ci}
231e41f4b71Sopenharmony_ci```
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci## zlib.decompressFile<sup>9+</sup>
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_cidecompressFile(inFile: string, outFile: string, options: Options, callback: AsyncCallback\<void>): void
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ci解压文件,解压的结果,使用callback异步回调返回。成功时返回null,失败时返回错误码。
238e41f4b71Sopenharmony_ci
239e41f4b71Sopenharmony_ci> **说明:**
240e41f4b71Sopenharmony_ci>
241e41f4b71Sopenharmony_ci>为了避免路径穿越,从API version 13开始,inFile和outFile传入的参数不允许包含../,否则会返回900001、900002错误码。
242e41f4b71Sopenharmony_ci
243e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
244e41f4b71Sopenharmony_ci
245e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
246e41f4b71Sopenharmony_ci
247e41f4b71Sopenharmony_ci**参数:**
248e41f4b71Sopenharmony_ci
249e41f4b71Sopenharmony_ci| 参数名                  | 类型                | 必填 | 说明                                                         |
250e41f4b71Sopenharmony_ci| ----------------------- | ------------------- | ---- | ------------------------------------------------------------ |
251e41f4b71Sopenharmony_ci| inFile                  | string              | 是   | 指定的待解压缩文件的文件路径,文件后缀需要以.zip结尾。文件路径必须为沙箱路径,沙箱路径可以通过context获取,可参考[FA模型](../apis-ability-kit/js-apis-inner-app-context.md),[Stage模型](../apis-ability-kit/js-apis-inner-application-context.md)。 |
252e41f4b71Sopenharmony_ci| outFile                 | string              | 是   | 指定的解压后的文件夹路径,文件夹目录路径需要在系统中存在,不存在则会解压失败。路径必须为沙箱路径,沙箱路径可以通过context获取,具体方法可参考[application/context(Stage模型)](../apis-ability-kit/js-apis-inner-application-context.md)或 [app/context(FA模型)](../apis-ability-kit/js-apis-inner-app-context.md)。如果待解压的文件或文件夹在解压后的路径下已经存在,则会直接覆盖同名文件或同名文件夹中的同名文件。多个线程同时解压文件时,outFile不能相同。 |
253e41f4b71Sopenharmony_ci| options                 | [Options](#options) | 是   | 解压的配置参数。                                             |
254e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>            | 是   | 异步获取解压结果之后的回调。成功返回null,失败返回错误码。                                             |
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci**错误码:**
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
259e41f4b71Sopenharmony_ci
260e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                               |
261e41f4b71Sopenharmony_ci| -------- | --------------------------------------|
262e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
263e41f4b71Sopenharmony_ci| 900001   | The input source file is invalid.      |
264e41f4b71Sopenharmony_ci| 900002   | The input destination file is invalid. |
265e41f4b71Sopenharmony_ci| 900003 | The input source file is not in ZIP format or is damaged. |
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_ci**示例:**
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ci```ts
270e41f4b71Sopenharmony_ci// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/haps,也可以通过context获取。
271e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_cilet inFile = '/xx/xxx.zip';
274e41f4b71Sopenharmony_cilet outFileDir = '/xxx';
275e41f4b71Sopenharmony_cilet options: zlib.Options = {
276e41f4b71Sopenharmony_ci  level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
277e41f4b71Sopenharmony_ci};
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_citry {
280e41f4b71Sopenharmony_ci  zlib.decompressFile(inFile, outFileDir, options, (errData: BusinessError) => {
281e41f4b71Sopenharmony_ci    if (errData !== null) {
282e41f4b71Sopenharmony_ci      console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
283e41f4b71Sopenharmony_ci    }
284e41f4b71Sopenharmony_ci  })
285e41f4b71Sopenharmony_ci} catch (errData) {
286e41f4b71Sopenharmony_ci  let code = (errData as BusinessError).code;
287e41f4b71Sopenharmony_ci  let message = (errData as BusinessError).message;
288e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${code}  message:${message}`);
289e41f4b71Sopenharmony_ci}
290e41f4b71Sopenharmony_ci```
291e41f4b71Sopenharmony_ci
292e41f4b71Sopenharmony_ci## zlib.decompressFile<sup>9+</sup>
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_cidecompressFile(inFile: string, outFile: string, options?: Options): Promise\<void>
295e41f4b71Sopenharmony_ci
296e41f4b71Sopenharmony_ci解压文件,解压的结果,使用Promise异步返回,成功时返回null,失败时返回错误码。
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ci> **说明:**
299e41f4b71Sopenharmony_ci>
300e41f4b71Sopenharmony_ci>为了避免路径穿越,从API version 13开始,inFile和outFile传入的参数不允许包含../,否则会返回900001、900002错误码。
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_ci**参数:**
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_ci| 参数名  | 类型                | 必填 | 说明                                                         |
309e41f4b71Sopenharmony_ci| ------- | ------------------- | ---- | ------------------------------------------------------------ |
310e41f4b71Sopenharmony_ci| inFile  | string              | 是   | 指定的待解压缩文件的文件路径,文件后缀需要以.zip结尾。文件路径必须为沙箱路径,沙箱路径可以通过context获取,可参考[FA模型](../apis-ability-kit/js-apis-inner-app-context.md),[Stage模型](../apis-ability-kit/js-apis-inner-application-context.md)。 |
311e41f4b71Sopenharmony_ci| outFile | string              | 是   | 指定的解压后的文件夹路径,文件夹目录路径需要在系统中存在,不存在则会解压失败。路径必须为沙箱路径,沙箱路径可以通过context获取,具体方法可参考[application/context(Stage模型)](../apis-ability-kit/js-apis-inner-application-context.md)或 [app/context(FA模型)](../apis-ability-kit/js-apis-inner-app-context.md)。如果待解压的文件或文件夹在解压后的路径下已经存在,则会直接覆盖同名文件或同名文件夹中的同名文件。多个线程同时解压文件时,outFile不能相同。 |
312e41f4b71Sopenharmony_ci| options | [Options](#options) | 否   | 解压时的配置参数。                                           |
313e41f4b71Sopenharmony_ci
314e41f4b71Sopenharmony_ci**返回值:**
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ci| 类型           | 说明                    |
317e41f4b71Sopenharmony_ci| -------------- | ----------------------- |
318e41f4b71Sopenharmony_ci| Promise\<void> | Promise对象,无返回值。 |
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci**错误码:**
321e41f4b71Sopenharmony_ci
322e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                               |
325e41f4b71Sopenharmony_ci| ------ | ------------------------------------- |
326e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
327e41f4b71Sopenharmony_ci| 900001 | The input source file is invalid.      |
328e41f4b71Sopenharmony_ci| 900002 | The input destination file is invalid. |
329e41f4b71Sopenharmony_ci| 900003 | The input source file is not in ZIP format or is damaged. |
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci**示例:**
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci```ts
334e41f4b71Sopenharmony_ci// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/haps,也可以通过context获取。
335e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
336e41f4b71Sopenharmony_ci
337e41f4b71Sopenharmony_cilet inFile = '/xx/xxx.zip';
338e41f4b71Sopenharmony_cilet outFileDir = '/xxx';
339e41f4b71Sopenharmony_cilet options: zlib.Options = {
340e41f4b71Sopenharmony_ci  level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
341e41f4b71Sopenharmony_ci};
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_citry {
344e41f4b71Sopenharmony_ci  zlib.decompressFile(inFile, outFileDir, options).then((data: void) => {
345e41f4b71Sopenharmony_ci    console.info('decompressFile success. data: ' + JSON.stringify(data));
346e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
347e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
348e41f4b71Sopenharmony_ci  })
349e41f4b71Sopenharmony_ci} catch (errData) {
350e41f4b71Sopenharmony_ci  let code = (errData as BusinessError).code;
351e41f4b71Sopenharmony_ci  let message = (errData as BusinessError).message;
352e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${code}  message:${message}`);
353e41f4b71Sopenharmony_ci}
354e41f4b71Sopenharmony_ci```
355e41f4b71Sopenharmony_ci
356e41f4b71Sopenharmony_ci## zlib.decompressFile<sup>10+</sup>
357e41f4b71Sopenharmony_ci
358e41f4b71Sopenharmony_cidecompressFile(inFile: string, outFile: string, callback: AsyncCallback\<void\>): void
359e41f4b71Sopenharmony_ci
360e41f4b71Sopenharmony_ci解压文件,解压的结果,使用callback异步回调返回。成功时返回null,失败时返回错误码。
361e41f4b71Sopenharmony_ci
362e41f4b71Sopenharmony_ci> **说明:**
363e41f4b71Sopenharmony_ci>
364e41f4b71Sopenharmony_ci>为了避免路径穿越,从API version 13开始,inFile和outFile传入的参数不允许包含../,否则会返回900001、900002错误码。
365e41f4b71Sopenharmony_ci
366e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
367e41f4b71Sopenharmony_ci
368e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci**参数:**
371e41f4b71Sopenharmony_ci
372e41f4b71Sopenharmony_ci| 参数名                  | 类型                | 必填 | 说明                                                         |
373e41f4b71Sopenharmony_ci| ----------------------- | ------------------- | ---- | ------------------------------------------------------------ |
374e41f4b71Sopenharmony_ci| inFile                  | string              | 是   | 指定的待解压缩文件的文件路径,文件后缀需要以.zip结尾。文件路径必须为沙箱路径,沙箱路径可以通过context获取,可参考[FA模型](../apis-ability-kit/js-apis-inner-app-context.md),[Stage模型](../apis-ability-kit/js-apis-inner-application-context.md)。 |
375e41f4b71Sopenharmony_ci| outFile                 | string              | 是   | 指定的解压后的文件夹路径,文件夹目录路径需要在系统中存在,不存在则会解压失败。路径必须为沙箱路径,沙箱路径可以通过context获取,具体方法可参考[application/context(Stage模型)](../apis-ability-kit/js-apis-inner-application-context.md)或 [app/context(FA模型)](../apis-ability-kit/js-apis-inner-app-context.md)。如果待解压的文件或文件夹在解压后的路径下已经存在,则会直接覆盖同名文件或同名文件夹中的同名文件。多个线程同时解压文件时,outFile不能相同。 |
376e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>            | 是   | 异步获取解压结果之后的回调。成功返回null,失败返回错误码。                                             |
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci**错误码:**
379e41f4b71Sopenharmony_ci
380e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
381e41f4b71Sopenharmony_ci
382e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                               |
383e41f4b71Sopenharmony_ci| -------- | --------------------------------------|
384e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
385e41f4b71Sopenharmony_ci| 900001   | The input source file is invalid.      |
386e41f4b71Sopenharmony_ci| 900002   | The input destination file is invalid. |
387e41f4b71Sopenharmony_ci| 900003 | The input source file is not in ZIP format or is damaged. |
388e41f4b71Sopenharmony_ci
389e41f4b71Sopenharmony_ci**示例:**
390e41f4b71Sopenharmony_ci
391e41f4b71Sopenharmony_ci```ts
392e41f4b71Sopenharmony_ci// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/haps,也可以通过context获取。
393e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
394e41f4b71Sopenharmony_ci
395e41f4b71Sopenharmony_cilet inFile = '/xx/xxx.zip';
396e41f4b71Sopenharmony_cilet outFileDir = '/xxx';
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_citry {
399e41f4b71Sopenharmony_ci  zlib.decompressFile(inFile, outFileDir, (errData: BusinessError) => {
400e41f4b71Sopenharmony_ci    if (errData !== null) {
401e41f4b71Sopenharmony_ci      console.error(`decompressFile failed. code is ${errData.code}, message is ${errData.message}`);
402e41f4b71Sopenharmony_ci    }
403e41f4b71Sopenharmony_ci  })
404e41f4b71Sopenharmony_ci} catch (errData) {
405e41f4b71Sopenharmony_ci  let code = (errData as BusinessError).code;
406e41f4b71Sopenharmony_ci  let message = (errData as BusinessError).message;
407e41f4b71Sopenharmony_ci  console.error(`decompressFile failed. code is ${code}, message is ${message}`);
408e41f4b71Sopenharmony_ci}
409e41f4b71Sopenharmony_ci```
410e41f4b71Sopenharmony_ci
411e41f4b71Sopenharmony_ci## zlib.getOriginalSize<sup>12+</sup>
412e41f4b71Sopenharmony_ci
413e41f4b71Sopenharmony_cigetOriginalSize(compressedFile: string): Promise\<number>
414e41f4b71Sopenharmony_ci
415e41f4b71Sopenharmony_ci获取压缩文件的原始大小,使用Promise异步返回。成功时返回压缩文件的原始大小,失败时返回错误码。
416e41f4b71Sopenharmony_ci
417e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
418e41f4b71Sopenharmony_ci
419e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ci**参数:**
422e41f4b71Sopenharmony_ci
423e41f4b71Sopenharmony_ci| 参数名  | 类型                | 必填 | 说明                                                         |
424e41f4b71Sopenharmony_ci| ------- | ------------------- | ---- | ------------------------------------------------------------ |
425e41f4b71Sopenharmony_ci| compressedFile  | string              | 是   | 指定的压缩文件的文件路径,只支持zip格式压缩文件。文件路径必须为沙箱路径,沙箱路径可以通过context获取,可参考[FA模型](../apis-ability-kit/js-apis-inner-app-context.md),[Stage模型](../apis-ability-kit/js-apis-inner-application-context.md)。 |
426e41f4b71Sopenharmony_ci
427e41f4b71Sopenharmony_ci**返回值:**
428e41f4b71Sopenharmony_ci
429e41f4b71Sopenharmony_ci| 类型           | 说明                    |
430e41f4b71Sopenharmony_ci| -------------- | ----------------------- |
431e41f4b71Sopenharmony_ci| Promise\<number> | Promise对象,返回压缩文件的原始大小,单位字节。 |
432e41f4b71Sopenharmony_ci
433e41f4b71Sopenharmony_ci**错误码:**
434e41f4b71Sopenharmony_ci
435e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
436e41f4b71Sopenharmony_ci
437e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                               |
438e41f4b71Sopenharmony_ci| ------ | ------------------------------------- |
439e41f4b71Sopenharmony_ci| 401 | The parameter check failed. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
440e41f4b71Sopenharmony_ci| 900001 | The input source file is invalid.      |
441e41f4b71Sopenharmony_ci| 900003 | The input source file is not in ZIP format or is damaged. |
442e41f4b71Sopenharmony_ci
443e41f4b71Sopenharmony_ci**示例:**
444e41f4b71Sopenharmony_ci
445e41f4b71Sopenharmony_ci```ts
446e41f4b71Sopenharmony_ci// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/temp,也可以通过context获取。
447e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_cilet compressedFile = '/data/storage/el2/base/temp/test.zip';
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_citry {
452e41f4b71Sopenharmony_ci  zlib.getOriginalSize(compressedFile).then((data: number) => {
453e41f4b71Sopenharmony_ci    console.info(`getOriginalSize success. getOriginalSize: ${data}`);
454e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
455e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
456e41f4b71Sopenharmony_ci  })
457e41f4b71Sopenharmony_ci} catch (errData) {
458e41f4b71Sopenharmony_ci  let code = (errData as BusinessError).code;
459e41f4b71Sopenharmony_ci  let message = (errData as BusinessError).message;
460e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${code}  message:${message}`);
461e41f4b71Sopenharmony_ci}
462e41f4b71Sopenharmony_ci```
463e41f4b71Sopenharmony_ci
464e41f4b71Sopenharmony_ci## zlib.compressFiles<sup>12+</sup>
465e41f4b71Sopenharmony_ci
466e41f4b71Sopenharmony_cicompressFiles(inFiles: Array&lt;string&gt;, outFile: string, options: Options): Promise&lt;void&gt;
467e41f4b71Sopenharmony_ci
468e41f4b71Sopenharmony_ci压缩指定的多个文件,使用Promise异步返回。成功时返回null,失败时返回错误码。
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
471e41f4b71Sopenharmony_ci
472e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ci**参数:**
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci| 参数名  | 类型                | 必填 | 说明                                                         |
477e41f4b71Sopenharmony_ci| ------- | ------------------- | ---- | ------------------------------------------------------------ |
478e41f4b71Sopenharmony_ci| inFiles | Array&lt;string&gt; | 是   | 指定压缩的文件夹路径或者文件路径,路径必须为沙箱路径,沙箱路径可以通过context获取,可参考[FA模型](../apis-ability-kit/js-apis-inner-app-context.md),[Stage模型](../apis-ability-kit/js-apis-inner-application-context.md)。待压缩的文件夹不可为空,否则使用[decompressFile](#zlibdecompressfile9)对压缩后的文件解压时会报错。 |
479e41f4b71Sopenharmony_ci| outFile | string              | 是   | 指定的压缩结果的文件路径。多个线程同时压缩文件时,outFile不能相同。 |
480e41f4b71Sopenharmony_ci| options | [Options](#options) | 是   | 压缩的配置参数。                                             |
481e41f4b71Sopenharmony_ci
482e41f4b71Sopenharmony_ci**返回值:**
483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_ci| 类型                | 说明                    |
485e41f4b71Sopenharmony_ci| ------------------- | ----------------------- |
486e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise对象,无返回值。 |
487e41f4b71Sopenharmony_ci
488e41f4b71Sopenharmony_ci**错误码:**
489e41f4b71Sopenharmony_ci
490e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
491e41f4b71Sopenharmony_ci
492e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
493e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
494e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
495e41f4b71Sopenharmony_ci| 900001   | The input source file is invalid.                            |
496e41f4b71Sopenharmony_ci| 900002   | The input destination file is invalid.                       |
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ci**示例:**
499e41f4b71Sopenharmony_ci
500e41f4b71Sopenharmony_ci```typescript
501e41f4b71Sopenharmony_ci// 代码中使用的路径需为应用的沙箱路径,如/data/storage/el2/base/temp,也可以通过context获取。
502e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
503e41f4b71Sopenharmony_ci
504e41f4b71Sopenharmony_cilet inFile = '/xxx/filename.xxx';
505e41f4b71Sopenharmony_cilet pathDir = '';
506e41f4b71Sopenharmony_cilet outFile = '/xxx/xxx.zip';
507e41f4b71Sopenharmony_cilet options: zlib.Options = {
508e41f4b71Sopenharmony_ci  level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
509e41f4b71Sopenharmony_ci  memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
510e41f4b71Sopenharmony_ci  strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
511e41f4b71Sopenharmony_ci};
512e41f4b71Sopenharmony_ci
513e41f4b71Sopenharmony_citry {
514e41f4b71Sopenharmony_ci  zlib.compressFiles([inFile, pathDir, pathDir], outFile, options).then((data: void) => {
515e41f4b71Sopenharmony_ci    console.info('compressFiles success. data: ' + JSON.stringify(data));
516e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
517e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
518e41f4b71Sopenharmony_ci  })
519e41f4b71Sopenharmony_ci} catch (errData) {
520e41f4b71Sopenharmony_ci  let code = (errData as BusinessError).code;
521e41f4b71Sopenharmony_ci  let message = (errData as BusinessError).message;
522e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${code}  message:${message}`);
523e41f4b71Sopenharmony_ci}
524e41f4b71Sopenharmony_ci```
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_ci## zlib.createChecksum<sup>12+</sup>
527e41f4b71Sopenharmony_ci
528e41f4b71Sopenharmony_cicreateChecksum(): Promise&lt;Checksum&gt;
529e41f4b71Sopenharmony_ci
530e41f4b71Sopenharmony_ci创建校验对象,使用Promise异步返回。成功时返回Checksum对象实例。
531e41f4b71Sopenharmony_ci
532e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
533e41f4b71Sopenharmony_ci
534e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
535e41f4b71Sopenharmony_ci
536e41f4b71Sopenharmony_ci**返回值:**
537e41f4b71Sopenharmony_ci
538e41f4b71Sopenharmony_ci| 类型                                   | 说明                            |
539e41f4b71Sopenharmony_ci| -------------------------------------- | ------------------------------- |
540e41f4b71Sopenharmony_ci| Promise&lt;[Checksum](#checksum12)&gt; | Promise对象。返回校验对象实例。 |
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ci**示例:**
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_ci```ts
545e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
546e41f4b71Sopenharmony_ci
547e41f4b71Sopenharmony_cizlib.createChecksum().then((data) => {
548e41f4b71Sopenharmony_ci  console.info('createChecksum success');
549e41f4b71Sopenharmony_ci})
550e41f4b71Sopenharmony_ci```
551e41f4b71Sopenharmony_ci
552e41f4b71Sopenharmony_ci## zlib.createChecksumSync<sup>12+</sup>
553e41f4b71Sopenharmony_ci
554e41f4b71Sopenharmony_cicreateChecksumSync():  Checksum
555e41f4b71Sopenharmony_ci
556e41f4b71Sopenharmony_ci创建校验对象。成功时返回Checksum对象实例。
557e41f4b71Sopenharmony_ci
558e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
559e41f4b71Sopenharmony_ci
560e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
561e41f4b71Sopenharmony_ci
562e41f4b71Sopenharmony_ci**返回值:**
563e41f4b71Sopenharmony_ci
564e41f4b71Sopenharmony_ci| 类型                    | 说明           |
565e41f4b71Sopenharmony_ci| ----------------------- | -------------- |
566e41f4b71Sopenharmony_ci| [Checksum](#checksum12) | 校验对象实例。 |
567e41f4b71Sopenharmony_ci
568e41f4b71Sopenharmony_ci**示例:**
569e41f4b71Sopenharmony_ci
570e41f4b71Sopenharmony_ci```ts
571e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
572e41f4b71Sopenharmony_ci
573e41f4b71Sopenharmony_cilet checksum = zlib.createChecksumSync()
574e41f4b71Sopenharmony_ci```
575e41f4b71Sopenharmony_ci
576e41f4b71Sopenharmony_ci## Checksum<sup>12+</sup>
577e41f4b71Sopenharmony_ci
578e41f4b71Sopenharmony_ci校验对象。
579e41f4b71Sopenharmony_ci
580e41f4b71Sopenharmony_ci### adler32<sup>12+</sup>
581e41f4b71Sopenharmony_ci
582e41f4b71Sopenharmony_ciadler32(adler: number, buf: ArrayBuffer): Promise&lt;number&gt;
583e41f4b71Sopenharmony_ci
584e41f4b71Sopenharmony_ci计算Adler-32校验和,使用Promise异步返回。成功时返回计算后的Adler-32校验和,失败时返回错误码。
585e41f4b71Sopenharmony_ci
586e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
587e41f4b71Sopenharmony_ci
588e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
589e41f4b71Sopenharmony_ci
590e41f4b71Sopenharmony_ci**参数:**
591e41f4b71Sopenharmony_ci
592e41f4b71Sopenharmony_ci| 参数名 | 类型        | 必填 | 说明                     |
593e41f4b71Sopenharmony_ci| ------ | ----------- | ---- | ------------------------ |
594e41f4b71Sopenharmony_ci| adler  | number      | 是   | Adler-32校验和的初始值。 |
595e41f4b71Sopenharmony_ci| buf    | ArrayBuffer | 是   | 计算校验和数据缓冲区。   |
596e41f4b71Sopenharmony_ci
597e41f4b71Sopenharmony_ci**返回值:**
598e41f4b71Sopenharmony_ci
599e41f4b71Sopenharmony_ci| 类型                  | 说明                                      |
600e41f4b71Sopenharmony_ci| --------------------- | ----------------------------------------- |
601e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象。返回计算后的Adler-32校验和。 |
602e41f4b71Sopenharmony_ci
603e41f4b71Sopenharmony_ci**错误码:**
604e41f4b71Sopenharmony_ci
605e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
606e41f4b71Sopenharmony_ci
607e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                               |
608e41f4b71Sopenharmony_ci| -------- | --------------------------------------|
609e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
610e41f4b71Sopenharmony_ci
611e41f4b71Sopenharmony_ci**示例:**
612e41f4b71Sopenharmony_ci
613e41f4b71Sopenharmony_ci```ts
614e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
615e41f4b71Sopenharmony_ci
616e41f4b71Sopenharmony_cilet str = 'hello world!';
617e41f4b71Sopenharmony_cilet arrayBufferIn = new ArrayBuffer(12);
618e41f4b71Sopenharmony_cilet data = new Uint8Array(arrayBufferIn);
619e41f4b71Sopenharmony_ci
620e41f4b71Sopenharmony_cifor (let i = 0, j = str.length; i < j; i++) {
621e41f4b71Sopenharmony_ci  data[i] = str.charCodeAt(i);
622e41f4b71Sopenharmony_ci}
623e41f4b71Sopenharmony_ci
624e41f4b71Sopenharmony_cilet checksum = zlib.createChecksumSync()
625e41f4b71Sopenharmony_ci
626e41f4b71Sopenharmony_cichecksum.adler32(0, arrayBufferIn).then(data => {
627e41f4b71Sopenharmony_ci  console.info('adler32 success', data);
628e41f4b71Sopenharmony_ci})
629e41f4b71Sopenharmony_ci```
630e41f4b71Sopenharmony_ci
631e41f4b71Sopenharmony_ci### adler32Combine<sup>12+</sup>
632e41f4b71Sopenharmony_ci
633e41f4b71Sopenharmony_ciadler32Combine(adler1: number, adler2: number, len2: number): Promise&lt;number&gt;
634e41f4b71Sopenharmony_ci
635e41f4b71Sopenharmony_ci将两个Adler-32校验和合并,使用Promise异步返回。成功时返回合并后的Adler-32校验和,失败时返回错误码。
636e41f4b71Sopenharmony_ci
637e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
638e41f4b71Sopenharmony_ci
639e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
640e41f4b71Sopenharmony_ci
641e41f4b71Sopenharmony_ci**参数:**
642e41f4b71Sopenharmony_ci
643e41f4b71Sopenharmony_ci| 参数名 | 类型   | 必填 | 说明                                 |
644e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------ |
645e41f4b71Sopenharmony_ci| adler1 | number | 是   | 第一个要合并的Adler-32校验和。       |
646e41f4b71Sopenharmony_ci| adler2 | number | 是   | 第二个要合并的Adler-32校验和。       |
647e41f4b71Sopenharmony_ci| len2   | number | 是   | 第二个Adler-32校验和的数据块的长度。 |
648e41f4b71Sopenharmony_ci
649e41f4b71Sopenharmony_ci**返回值:**
650e41f4b71Sopenharmony_ci
651e41f4b71Sopenharmony_ci| 类型                  | 说明                                      |
652e41f4b71Sopenharmony_ci| --------------------- | ----------------------------------------- |
653e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象。返回合并后的Adler-32校验和。 |
654e41f4b71Sopenharmony_ci
655e41f4b71Sopenharmony_ci**错误码:**
656e41f4b71Sopenharmony_ci
657e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
658e41f4b71Sopenharmony_ci
659e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                               |
660e41f4b71Sopenharmony_ci| -------- | --------------------------------------|
661e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
662e41f4b71Sopenharmony_ci
663e41f4b71Sopenharmony_ci**示例:**
664e41f4b71Sopenharmony_ci
665e41f4b71Sopenharmony_ci```ts
666e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
667e41f4b71Sopenharmony_ci
668e41f4b71Sopenharmony_ciasync function demo() {
669e41f4b71Sopenharmony_ci  let str = 'hello world!';
670e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(12);
671e41f4b71Sopenharmony_ci  let data = new Uint8Array(arrayBufferIn);
672e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
673e41f4b71Sopenharmony_ci    data[i] = str.charCodeAt(i);
674e41f4b71Sopenharmony_ci  }
675e41f4b71Sopenharmony_ci  let checksum = zlib.createChecksumSync()
676e41f4b71Sopenharmony_ci  let adler1 = 0;
677e41f4b71Sopenharmony_ci  let adler2 = 1;
678e41f4b71Sopenharmony_ci  await checksum.adler32(0, arrayBufferIn).then(data => {
679e41f4b71Sopenharmony_ci    console.info('adler32 success', data);
680e41f4b71Sopenharmony_ci    adler1 = data;
681e41f4b71Sopenharmony_ci  })
682e41f4b71Sopenharmony_ci  await checksum.adler32(1, arrayBufferIn).then(data => {
683e41f4b71Sopenharmony_ci    console.info('adler32 success', data);
684e41f4b71Sopenharmony_ci    adler2 = data;
685e41f4b71Sopenharmony_ci  })
686e41f4b71Sopenharmony_ci  await checksum.adler32Combine(adler1, adler2, 12).then((data) => {
687e41f4b71Sopenharmony_ci    console.info('adler32Combine success', data);
688e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
689e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
690e41f4b71Sopenharmony_ci  })
691e41f4b71Sopenharmony_ci}
692e41f4b71Sopenharmony_ci```
693e41f4b71Sopenharmony_ci
694e41f4b71Sopenharmony_ci### crc32<sup>12+</sup>
695e41f4b71Sopenharmony_ci
696e41f4b71Sopenharmony_cicrc32(crc: number, buf: ArrayBuffer): Promise&lt;number&gt;
697e41f4b71Sopenharmony_ci
698e41f4b71Sopenharmony_ci更新CRC-32校验,使用Promise异步返回。成功时返回更新后的CRC-32校验,失败时返回错误码。
699e41f4b71Sopenharmony_ci
700e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
701e41f4b71Sopenharmony_ci
702e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
703e41f4b71Sopenharmony_ci
704e41f4b71Sopenharmony_ci**参数:**
705e41f4b71Sopenharmony_ci
706e41f4b71Sopenharmony_ci| 参数名 | 类型        | 必填 | 说明                 |
707e41f4b71Sopenharmony_ci| ------ | ----------- | ---- | -------------------- |
708e41f4b71Sopenharmony_ci| crc    | number      | 是   | CRC-32校验的初始值。 |
709e41f4b71Sopenharmony_ci| buf    | ArrayBuffer | 是   | 计算校验数据缓冲区。 |
710e41f4b71Sopenharmony_ci
711e41f4b71Sopenharmony_ci**返回值:**
712e41f4b71Sopenharmony_ci
713e41f4b71Sopenharmony_ci| 类型                  | 说明                                  |
714e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------- |
715e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象。返回更新后的CRC-32校验。 |
716e41f4b71Sopenharmony_ci
717e41f4b71Sopenharmony_ci**错误码:**
718e41f4b71Sopenharmony_ci
719e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
720e41f4b71Sopenharmony_ci
721e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                               |
722e41f4b71Sopenharmony_ci| -------- | --------------------------------------|
723e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
724e41f4b71Sopenharmony_ci
725e41f4b71Sopenharmony_ci**示例:**
726e41f4b71Sopenharmony_ci
727e41f4b71Sopenharmony_ci```ts
728e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_cilet str = 'hello world!';
731e41f4b71Sopenharmony_cilet arrayBufferIn = new ArrayBuffer(12);
732e41f4b71Sopenharmony_cilet data = new Uint8Array(arrayBufferIn);
733e41f4b71Sopenharmony_ci
734e41f4b71Sopenharmony_cifor (let i = 0, j = str.length; i < j; i++) {
735e41f4b71Sopenharmony_ci  data[i] = str.charCodeAt(i);
736e41f4b71Sopenharmony_ci}
737e41f4b71Sopenharmony_ci
738e41f4b71Sopenharmony_cilet checksum = zlib.createChecksumSync()
739e41f4b71Sopenharmony_ci
740e41f4b71Sopenharmony_cichecksum.crc32(0, arrayBufferIn).then((data) => {
741e41f4b71Sopenharmony_ci  console.info('crc32 success', data);
742e41f4b71Sopenharmony_ci}).catch((errData: BusinessError) => {
743e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
744e41f4b71Sopenharmony_ci})
745e41f4b71Sopenharmony_ci```
746e41f4b71Sopenharmony_ci
747e41f4b71Sopenharmony_ci### crc32Combine<sup>12+</sup>
748e41f4b71Sopenharmony_ci
749e41f4b71Sopenharmony_cicrc32Combine(crc1: number, crc2: number, len2: number): Promise&lt;number&gt;
750e41f4b71Sopenharmony_ci
751e41f4b71Sopenharmony_ci将两个CRC-32校验合并,使用Promise异步返回。成功时返回合并后的CRC-32校验,失败时返回错误码。
752e41f4b71Sopenharmony_ci
753e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
754e41f4b71Sopenharmony_ci
755e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
756e41f4b71Sopenharmony_ci
757e41f4b71Sopenharmony_ci**参数:**
758e41f4b71Sopenharmony_ci
759e41f4b71Sopenharmony_ci| 参数名 | 类型   | 必填 | 说明                             |
760e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------------- |
761e41f4b71Sopenharmony_ci| crc1 | number | 是   | 第一个要合并的CRC-32校验。       |
762e41f4b71Sopenharmony_ci| crc2 | number | 是   | 第二个要合并的CRC-32校验。       |
763e41f4b71Sopenharmony_ci| len2   | number | 是   | 第二个CRC-32校验的数据块的长度。 |
764e41f4b71Sopenharmony_ci
765e41f4b71Sopenharmony_ci**返回值:**
766e41f4b71Sopenharmony_ci
767e41f4b71Sopenharmony_ci| 类型                  | 说明                                  |
768e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------- |
769e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象。返回合并后的CRC-32校验。 |
770e41f4b71Sopenharmony_ci
771e41f4b71Sopenharmony_ci**错误码:**
772e41f4b71Sopenharmony_ci
773e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
774e41f4b71Sopenharmony_ci
775e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                               |
776e41f4b71Sopenharmony_ci| -------- | --------------------------------------|
777e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
778e41f4b71Sopenharmony_ci
779e41f4b71Sopenharmony_ci**示例:**
780e41f4b71Sopenharmony_ci
781e41f4b71Sopenharmony_ci```ts
782e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
783e41f4b71Sopenharmony_ci
784e41f4b71Sopenharmony_ciasync function demo() {
785e41f4b71Sopenharmony_ci  let str = 'hello world!';
786e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(12);
787e41f4b71Sopenharmony_ci  let data = new Uint8Array(arrayBufferIn);
788e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
789e41f4b71Sopenharmony_ci    data[i] = str.charCodeAt(i);
790e41f4b71Sopenharmony_ci  }
791e41f4b71Sopenharmony_ci  let checksum = zlib.createChecksumSync()
792e41f4b71Sopenharmony_ci  let crc1 = 0;
793e41f4b71Sopenharmony_ci  let crc2 = 1;
794e41f4b71Sopenharmony_ci  await checksum.crc32(0, arrayBufferIn).then(data => {
795e41f4b71Sopenharmony_ci    console.info('crc32 success', data);
796e41f4b71Sopenharmony_ci    crc1 = data;
797e41f4b71Sopenharmony_ci  })
798e41f4b71Sopenharmony_ci  await checksum.crc32(1, arrayBufferIn).then(data => {
799e41f4b71Sopenharmony_ci    console.info('crc32 success', data);
800e41f4b71Sopenharmony_ci    crc2 = data;
801e41f4b71Sopenharmony_ci  })
802e41f4b71Sopenharmony_ci  await checksum.crc32Combine(crc1, crc2, 12).then((data) => {
803e41f4b71Sopenharmony_ci    console.info('crc32Combine success', data);
804e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
805e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
806e41f4b71Sopenharmony_ci  })
807e41f4b71Sopenharmony_ci}
808e41f4b71Sopenharmony_ci```
809e41f4b71Sopenharmony_ci
810e41f4b71Sopenharmony_ci### crc64<sup>12+</sup>
811e41f4b71Sopenharmony_ci
812e41f4b71Sopenharmony_cicrc64(crc: number, buf: ArrayBuffer): Promise&lt;number&gt;
813e41f4b71Sopenharmony_ci
814e41f4b71Sopenharmony_ci更新CRC-64校验,使用Promise异步返回。成功时返回更新后的CRC-64校验,失败时返回错误码。
815e41f4b71Sopenharmony_ci
816e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
817e41f4b71Sopenharmony_ci
818e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
819e41f4b71Sopenharmony_ci
820e41f4b71Sopenharmony_ci**参数:**
821e41f4b71Sopenharmony_ci
822e41f4b71Sopenharmony_ci| 参数名 | 类型        | 必填 | 说明                 |
823e41f4b71Sopenharmony_ci| ------ | ----------- | ---- | -------------------- |
824e41f4b71Sopenharmony_ci| crc    | number      | 是   | CRC-64校验的初始值。 |
825e41f4b71Sopenharmony_ci| buf    | ArrayBuffer | 是   | 计算校验数据缓冲区。 |
826e41f4b71Sopenharmony_ci
827e41f4b71Sopenharmony_ci**返回值:**
828e41f4b71Sopenharmony_ci
829e41f4b71Sopenharmony_ci| 类型                  | 说明                                  |
830e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------- |
831e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象。返回更新后的CRC-64校验。 |
832e41f4b71Sopenharmony_ci
833e41f4b71Sopenharmony_ci**错误码:**
834e41f4b71Sopenharmony_ci
835e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
836e41f4b71Sopenharmony_ci
837e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                               |
838e41f4b71Sopenharmony_ci| -------- | --------------------------------------|
839e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
840e41f4b71Sopenharmony_ci
841e41f4b71Sopenharmony_ci**示例:**
842e41f4b71Sopenharmony_ci
843e41f4b71Sopenharmony_ci```ts
844e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
845e41f4b71Sopenharmony_ci
846e41f4b71Sopenharmony_cilet str = 'hello world!';
847e41f4b71Sopenharmony_cilet arrayBufferIn = new ArrayBuffer(12);
848e41f4b71Sopenharmony_cilet data = new Uint8Array(arrayBufferIn);
849e41f4b71Sopenharmony_ci
850e41f4b71Sopenharmony_cifor (let i = 0, j = str.length; i < j; i++) {
851e41f4b71Sopenharmony_ci  data[i] = str.charCodeAt(i);
852e41f4b71Sopenharmony_ci}
853e41f4b71Sopenharmony_ci
854e41f4b71Sopenharmony_cilet checksum = zlib.createChecksumSync()
855e41f4b71Sopenharmony_ci
856e41f4b71Sopenharmony_cichecksum.crc64(0, arrayBufferIn).then((data) => {
857e41f4b71Sopenharmony_ci  console.info('crc64 success', data);
858e41f4b71Sopenharmony_ci}).catch((errData: BusinessError) => {
859e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
860e41f4b71Sopenharmony_ci})
861e41f4b71Sopenharmony_ci```
862e41f4b71Sopenharmony_ci
863e41f4b71Sopenharmony_ci### getCrcTable<sup>12+</sup>
864e41f4b71Sopenharmony_ci
865e41f4b71Sopenharmony_cigetCrcTable(): Promise&lt;Array&lt;number&gt;&gt;
866e41f4b71Sopenharmony_ci
867e41f4b71Sopenharmony_ci输出CRC-32校验表,使用Promise异步返回。成功时返回CRC-32校验表。
868e41f4b71Sopenharmony_ci
869e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
870e41f4b71Sopenharmony_ci
871e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
872e41f4b71Sopenharmony_ci
873e41f4b71Sopenharmony_ci**返回值:**
874e41f4b71Sopenharmony_ci
875e41f4b71Sopenharmony_ci| 类型                               | 说明                            |
876e41f4b71Sopenharmony_ci| ---------------------------------- | ------------------------------- |
877e41f4b71Sopenharmony_ci| Promise&lt;Array&lt;number&gt;&gt; | Promise对象。返回CRC-32校验表。 |
878e41f4b71Sopenharmony_ci
879e41f4b71Sopenharmony_ci**示例:**
880e41f4b71Sopenharmony_ci
881e41f4b71Sopenharmony_ci```ts
882e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
883e41f4b71Sopenharmony_ci
884e41f4b71Sopenharmony_cilet checksum = zlib.createChecksumSync()
885e41f4b71Sopenharmony_ci
886e41f4b71Sopenharmony_cichecksum.getCrcTable().then((data) => {
887e41f4b71Sopenharmony_ci  console.info('getCrcTable success');
888e41f4b71Sopenharmony_ci}).catch((errData: BusinessError) => {
889e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
890e41f4b71Sopenharmony_ci})
891e41f4b71Sopenharmony_ci```
892e41f4b71Sopenharmony_ci
893e41f4b71Sopenharmony_ci### getCrc64Table<sup>12+</sup>
894e41f4b71Sopenharmony_ci
895e41f4b71Sopenharmony_cigetCrc64Table(): Promise&lt;Array&lt;number&gt;&gt;
896e41f4b71Sopenharmony_ci
897e41f4b71Sopenharmony_ci输出CRC-64校验表,使用Promise异步返回。成功时返回CRC-64校验表。
898e41f4b71Sopenharmony_ci
899e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
900e41f4b71Sopenharmony_ci
901e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
902e41f4b71Sopenharmony_ci
903e41f4b71Sopenharmony_ci**返回值:**
904e41f4b71Sopenharmony_ci
905e41f4b71Sopenharmony_ci| 类型                               | 说明                            |
906e41f4b71Sopenharmony_ci| ---------------------------------- | ------------------------------- |
907e41f4b71Sopenharmony_ci| Promise&lt;Array&lt;number&gt;&gt; | Promise对象。返回CRC-64校验表。 |
908e41f4b71Sopenharmony_ci
909e41f4b71Sopenharmony_ci**示例:**
910e41f4b71Sopenharmony_ci
911e41f4b71Sopenharmony_ci```ts
912e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
913e41f4b71Sopenharmony_ci
914e41f4b71Sopenharmony_cilet checksum = zlib.createChecksumSync()
915e41f4b71Sopenharmony_ci
916e41f4b71Sopenharmony_cichecksum.getCrc64Table().then((data) => {
917e41f4b71Sopenharmony_ci  console.info('getCrc64Table success');
918e41f4b71Sopenharmony_ci}).catch((errData: BusinessError) => {
919e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
920e41f4b71Sopenharmony_ci})
921e41f4b71Sopenharmony_ci```
922e41f4b71Sopenharmony_ci
923e41f4b71Sopenharmony_ci## zlib.createZip<sup>12+</sup>
924e41f4b71Sopenharmony_ci
925e41f4b71Sopenharmony_cicreateZip(): Promise&lt;Zip&gt;
926e41f4b71Sopenharmony_ci
927e41f4b71Sopenharmony_ci创建压缩解压缩对象实例,使用Promise异步返回,成功时返回压缩解压缩对象实例。
928e41f4b71Sopenharmony_ci
929e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
930e41f4b71Sopenharmony_ci
931e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
932e41f4b71Sopenharmony_ci
933e41f4b71Sopenharmony_ci**返回值:**
934e41f4b71Sopenharmony_ci
935e41f4b71Sopenharmony_ci| 类型                         | 说明                                  |
936e41f4b71Sopenharmony_ci| ---------------------------- | ------------------------------------- |
937e41f4b71Sopenharmony_ci| Promise&lt;[Zip](#zip12)&gt; | Promise对象。返回压缩解压缩对象实例。 |
938e41f4b71Sopenharmony_ci
939e41f4b71Sopenharmony_ci**示例:**
940e41f4b71Sopenharmony_ci
941e41f4b71Sopenharmony_ci```ts
942e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
943e41f4b71Sopenharmony_ci
944e41f4b71Sopenharmony_cilet zip = zlib.createZipSync();
945e41f4b71Sopenharmony_ci
946e41f4b71Sopenharmony_cizlib.createZip().then(data => {
947e41f4b71Sopenharmony_ci  console.info('createZip success');
948e41f4b71Sopenharmony_ci}).catch((errData: BusinessError) => {
949e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
950e41f4b71Sopenharmony_ci})
951e41f4b71Sopenharmony_ci```
952e41f4b71Sopenharmony_ci
953e41f4b71Sopenharmony_ci## zlib.createZipSync<sup>12+</sup>
954e41f4b71Sopenharmony_ci
955e41f4b71Sopenharmony_cicreateZipSync(): Zip
956e41f4b71Sopenharmony_ci
957e41f4b71Sopenharmony_ci创建压缩解压缩对象实例,成功时返回压缩解压缩对象实例。
958e41f4b71Sopenharmony_ci
959e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
960e41f4b71Sopenharmony_ci
961e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
962e41f4b71Sopenharmony_ci
963e41f4b71Sopenharmony_ci**返回值:**
964e41f4b71Sopenharmony_ci
965e41f4b71Sopenharmony_ci| 类型          | 说明                     |
966e41f4b71Sopenharmony_ci| ------------- | ------------------------ |
967e41f4b71Sopenharmony_ci| [Zip](#zip12) | 返回压缩解压缩对象实例。 |
968e41f4b71Sopenharmony_ci
969e41f4b71Sopenharmony_ci**示例:**
970e41f4b71Sopenharmony_ci
971e41f4b71Sopenharmony_ci```ts
972e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
973e41f4b71Sopenharmony_ci
974e41f4b71Sopenharmony_cilet zip = zlib.createZipSync();
975e41f4b71Sopenharmony_ci```
976e41f4b71Sopenharmony_ci
977e41f4b71Sopenharmony_ci## Zip<sup>12+</sup>
978e41f4b71Sopenharmony_ci
979e41f4b71Sopenharmony_ci压缩解压缩对象实例。
980e41f4b71Sopenharmony_ci
981e41f4b71Sopenharmony_ci### getZStream<sup>12+</sup>
982e41f4b71Sopenharmony_ci
983e41f4b71Sopenharmony_cigetZStream(): Promise&lt;ZStream&gt;
984e41f4b71Sopenharmony_ci
985e41f4b71Sopenharmony_ci输出流,使用Promise异步返回。成功时返回zlib流。
986e41f4b71Sopenharmony_ci
987e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
988e41f4b71Sopenharmony_ci
989e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
990e41f4b71Sopenharmony_ci
991e41f4b71Sopenharmony_ci**返回值:**
992e41f4b71Sopenharmony_ci
993e41f4b71Sopenharmony_ci| 类型                                 | 说明                      |
994e41f4b71Sopenharmony_ci| ------------------------------------ | ------------------------- |
995e41f4b71Sopenharmony_ci| Promise&lt;[ZStream](#zstream12)&gt; | Promise对象。返回zlib流。 |
996e41f4b71Sopenharmony_ci
997e41f4b71Sopenharmony_ci**示例:**
998e41f4b71Sopenharmony_ci
999e41f4b71Sopenharmony_ci```ts
1000e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
1001e41f4b71Sopenharmony_ci
1002e41f4b71Sopenharmony_cilet zip = zlib.createZipSync();
1003e41f4b71Sopenharmony_ci
1004e41f4b71Sopenharmony_cizip.getZStream().then(data => {
1005e41f4b71Sopenharmony_ci  console.info('getZStream success');
1006e41f4b71Sopenharmony_ci})
1007e41f4b71Sopenharmony_ci```
1008e41f4b71Sopenharmony_ci
1009e41f4b71Sopenharmony_ci### zlibVersion<sup>12+</sup>
1010e41f4b71Sopenharmony_ci
1011e41f4b71Sopenharmony_cizlibVersion(): Promise&lt;string&gt;
1012e41f4b71Sopenharmony_ci
1013e41f4b71Sopenharmony_ci获取当前链接的zlib库的版本信息,使用Promise异步返回。成功时返回当前zlib库的版本信息。
1014e41f4b71Sopenharmony_ci
1015e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1016e41f4b71Sopenharmony_ci
1017e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1018e41f4b71Sopenharmony_ci
1019e41f4b71Sopenharmony_ci**返回值:**
1020e41f4b71Sopenharmony_ci
1021e41f4b71Sopenharmony_ci| 类型                  | 说明                                    |
1022e41f4b71Sopenharmony_ci| --------------------- | --------------------------------------- |
1023e41f4b71Sopenharmony_ci| Promise&lt;string&gt; | Promise对象。返回当前zlib库的版本信息。 |
1024e41f4b71Sopenharmony_ci
1025e41f4b71Sopenharmony_ci**示例:**
1026e41f4b71Sopenharmony_ci
1027e41f4b71Sopenharmony_ci```ts
1028e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
1029e41f4b71Sopenharmony_ci
1030e41f4b71Sopenharmony_cilet zip = zlib.createZipSync();
1031e41f4b71Sopenharmony_ci
1032e41f4b71Sopenharmony_cizip.zlibVersion().then((data) => {
1033e41f4b71Sopenharmony_ci  console.info('zlibVersion success')
1034e41f4b71Sopenharmony_ci})
1035e41f4b71Sopenharmony_ci```
1036e41f4b71Sopenharmony_ci
1037e41f4b71Sopenharmony_ci### zlibCompileFlags<sup>12+</sup>
1038e41f4b71Sopenharmony_ci
1039e41f4b71Sopenharmony_cizlibCompileFlags(): Promise&lt;number&gt;
1040e41f4b71Sopenharmony_ci
1041e41f4b71Sopenharmony_ci返回指示编译时选项的标志,使用Promise异步返回。成功时返回指示编译时选项的标志。
1042e41f4b71Sopenharmony_ci
1043e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1044e41f4b71Sopenharmony_ci
1045e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1046e41f4b71Sopenharmony_ci
1047e41f4b71Sopenharmony_ci**返回值:**
1048e41f4b71Sopenharmony_ci
1049e41f4b71Sopenharmony_ci| 类型                  | 说明                                    |
1050e41f4b71Sopenharmony_ci| --------------------- | --------------------------------------- |
1051e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象。返回指示编译时选项的标志。 |
1052e41f4b71Sopenharmony_ci
1053e41f4b71Sopenharmony_ci**示例:**
1054e41f4b71Sopenharmony_ci
1055e41f4b71Sopenharmony_ci```ts
1056e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
1057e41f4b71Sopenharmony_ci
1058e41f4b71Sopenharmony_cilet zip = zlib.createZipSync();
1059e41f4b71Sopenharmony_ci
1060e41f4b71Sopenharmony_cizip.zlibCompileFlags().then((data) => {
1061e41f4b71Sopenharmony_ci  console.info('zlibCompileFlags success')
1062e41f4b71Sopenharmony_ci})
1063e41f4b71Sopenharmony_ci```
1064e41f4b71Sopenharmony_ci
1065e41f4b71Sopenharmony_ci### compress<sup>12+</sup>
1066e41f4b71Sopenharmony_ci
1067e41f4b71Sopenharmony_cicompress(dest: ArrayBuffer, source: ArrayBuffer, sourceLen?: number): Promise&lt;ZipOutputInfo&gt;
1068e41f4b71Sopenharmony_ci
1069e41f4b71Sopenharmony_ci将源缓冲区压缩到目标缓冲区,使用Promise异步返回。成功时返回结果状态和目标缓冲区的总大小。
1070e41f4b71Sopenharmony_ci
1071e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1072e41f4b71Sopenharmony_ci
1073e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1074e41f4b71Sopenharmony_ci
1075e41f4b71Sopenharmony_ci**参数:**
1076e41f4b71Sopenharmony_ci
1077e41f4b71Sopenharmony_ci| 参数名    | 类型        | 必填 | 说明           |
1078e41f4b71Sopenharmony_ci| --------- | ----------- | ---- | -------------- |
1079e41f4b71Sopenharmony_ci| dest      | ArrayBuffer | 是   | 目标缓冲区。   |
1080e41f4b71Sopenharmony_ci| source    | ArrayBuffer | 是   | 源数据缓冲区。 |
1081e41f4b71Sopenharmony_ci| sourceLen | number      | 否   | 源数据长度。   |
1082e41f4b71Sopenharmony_ci
1083e41f4b71Sopenharmony_ci**返回值:**
1084e41f4b71Sopenharmony_ci
1085e41f4b71Sopenharmony_ci| 类型                                             | 说明                                            |
1086e41f4b71Sopenharmony_ci| ------------------------------------------------ | ----------------------------------------------- |
1087e41f4b71Sopenharmony_ci| Promise&lt;[ZipOutputInfo](#zipoutputinfo12)&gt; | Promise对象。返回结果状态和目标缓冲区的总大小。 |
1088e41f4b71Sopenharmony_ci
1089e41f4b71Sopenharmony_ci**错误码:**
1090e41f4b71Sopenharmony_ci
1091e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1092e41f4b71Sopenharmony_ci
1093e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1094e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1095e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1096e41f4b71Sopenharmony_ci| 17800007 | Buffer error.                                                |
1097e41f4b71Sopenharmony_ci
1098e41f4b71Sopenharmony_ci**示例:**
1099e41f4b71Sopenharmony_ci
1100e41f4b71Sopenharmony_ci```ts
1101e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1102e41f4b71Sopenharmony_ci
1103e41f4b71Sopenharmony_cilet str = 'hello world!';
1104e41f4b71Sopenharmony_cilet arrayBufferIn = new ArrayBuffer(str.length);
1105e41f4b71Sopenharmony_cilet byteArray = new Uint8Array(arrayBufferIn);
1106e41f4b71Sopenharmony_ci
1107e41f4b71Sopenharmony_cifor (let i = 0, j = str.length; i < j; i++) {
1108e41f4b71Sopenharmony_ci  byteArray[i] = str.charCodeAt(i)
1109e41f4b71Sopenharmony_ci}
1110e41f4b71Sopenharmony_ci
1111e41f4b71Sopenharmony_cilet arrayBufferOut = new ArrayBuffer(100);
1112e41f4b71Sopenharmony_cilet zip = zlib.createZipSync();
1113e41f4b71Sopenharmony_ci
1114e41f4b71Sopenharmony_cizip.compress(arrayBufferOut, arrayBufferOut, 20).then((data) => {
1115e41f4b71Sopenharmony_ci  console.info('compress success:');
1116e41f4b71Sopenharmony_ci}).catch((errData: BusinessError) => {
1117e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1118e41f4b71Sopenharmony_ci})
1119e41f4b71Sopenharmony_ci```
1120e41f4b71Sopenharmony_ci
1121e41f4b71Sopenharmony_ci### compress2<sup>12+</sup>
1122e41f4b71Sopenharmony_ci
1123e41f4b71Sopenharmony_cicompress2(dest: ArrayBuffer, source: ArrayBuffer, level: CompressLevel, sourceLen?: number): Promise&lt;ZipOutputInfo&gt;
1124e41f4b71Sopenharmony_ci
1125e41f4b71Sopenharmony_ci将源缓冲区压缩到目标缓冲区,使用Promise异步返回。成功时返回结果状态和目标缓冲区的总大小。
1126e41f4b71Sopenharmony_ci
1127e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1128e41f4b71Sopenharmony_ci
1129e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1130e41f4b71Sopenharmony_ci
1131e41f4b71Sopenharmony_ci**参数:**
1132e41f4b71Sopenharmony_ci
1133e41f4b71Sopenharmony_ci| 参数名    | 类型          | 必填 | 说明                                                 |
1134e41f4b71Sopenharmony_ci| --------- | ------------- | ---- | ---------------------------------------------------- |
1135e41f4b71Sopenharmony_ci| dest      | ArrayBuffer   | 是   | 目标缓冲区。                                         |
1136e41f4b71Sopenharmony_ci| source    | ArrayBuffer   | 是   | 源数据缓冲区。                                       |
1137e41f4b71Sopenharmony_ci| level     | CompressLevel | 是   | 参考[zip.CompressLevel枚举定义](#zipcompresslevel)。 |
1138e41f4b71Sopenharmony_ci| sourceLen | number        | 否   | 源数据长度。                                         |
1139e41f4b71Sopenharmony_ci
1140e41f4b71Sopenharmony_ci**返回值:**
1141e41f4b71Sopenharmony_ci
1142e41f4b71Sopenharmony_ci| 类型                                             | 说明                                            |
1143e41f4b71Sopenharmony_ci| ------------------------------------------------ | ----------------------------------------------- |
1144e41f4b71Sopenharmony_ci| Promise&lt;[ZipOutputInfo](#zipoutputinfo12)&gt; | Promise对象。返回结果状态和目标缓冲区的总大小。 |
1145e41f4b71Sopenharmony_ci
1146e41f4b71Sopenharmony_ci**错误码:**
1147e41f4b71Sopenharmony_ci
1148e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1149e41f4b71Sopenharmony_ci
1150e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1151e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1152e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1153e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
1154e41f4b71Sopenharmony_ci| 17800007 | Buffer error.                                                |
1155e41f4b71Sopenharmony_ci
1156e41f4b71Sopenharmony_ci**示例:**
1157e41f4b71Sopenharmony_ci
1158e41f4b71Sopenharmony_ci```ts
1159e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1160e41f4b71Sopenharmony_ci
1161e41f4b71Sopenharmony_cilet str = 'hello world!';
1162e41f4b71Sopenharmony_cilet arrayBufferIn = new ArrayBuffer(str.length);
1163e41f4b71Sopenharmony_cilet byteArray = new Uint8Array(arrayBufferIn);
1164e41f4b71Sopenharmony_ci
1165e41f4b71Sopenharmony_cifor (let i = 0, j = str.length; i < j; i++) {
1166e41f4b71Sopenharmony_ci  byteArray[i] = str.charCodeAt(i)
1167e41f4b71Sopenharmony_ci}
1168e41f4b71Sopenharmony_ci
1169e41f4b71Sopenharmony_cilet arrayBufferOut = new ArrayBuffer(100);
1170e41f4b71Sopenharmony_cilet zip = zlib.createZipSync();
1171e41f4b71Sopenharmony_ci
1172e41f4b71Sopenharmony_cizip.compress2(arrayBufferOut, arrayBufferIn, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
1173e41f4b71Sopenharmony_ci  console.info('compress2 success');
1174e41f4b71Sopenharmony_ci}).catch((errData: BusinessError) => {
1175e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1176e41f4b71Sopenharmony_ci})
1177e41f4b71Sopenharmony_ci```
1178e41f4b71Sopenharmony_ci
1179e41f4b71Sopenharmony_ci### uncompress<sup>12+</sup>
1180e41f4b71Sopenharmony_ci
1181e41f4b71Sopenharmony_ciuncompress(dest:ArrayBuffer, source: ArrayBuffer, sourceLen?: number): Promise&lt;ZipOutputInfo&gt;
1182e41f4b71Sopenharmony_ci
1183e41f4b71Sopenharmony_ci将压缩后的数据解压缩为原始的未压缩形式,使用Promise异步返回。成功时返回结果状态和目标缓冲区的总大小。
1184e41f4b71Sopenharmony_ci
1185e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1186e41f4b71Sopenharmony_ci
1187e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1188e41f4b71Sopenharmony_ci
1189e41f4b71Sopenharmony_ci**参数:**
1190e41f4b71Sopenharmony_ci
1191e41f4b71Sopenharmony_ci| 参数名    | 类型        | 必填 | 说明           |
1192e41f4b71Sopenharmony_ci| --------- | ----------- | ---- | -------------- |
1193e41f4b71Sopenharmony_ci| dest      | ArrayBuffer | 是   | 目标缓冲区。   |
1194e41f4b71Sopenharmony_ci| source    | ArrayBuffer | 是   | 源数据缓冲区。 |
1195e41f4b71Sopenharmony_ci| sourceLen | number      | 否   | 源数据长度。   |
1196e41f4b71Sopenharmony_ci
1197e41f4b71Sopenharmony_ci**返回值:**
1198e41f4b71Sopenharmony_ci
1199e41f4b71Sopenharmony_ci| 类型                                             | 说明                                            |
1200e41f4b71Sopenharmony_ci| ------------------------------------------------ | ----------------------------------------------- |
1201e41f4b71Sopenharmony_ci| Promise&lt;[ZipOutputInfo](#zipoutputinfo12)&gt; | Promise对象。返回结果状态和目标缓冲区的总大小。 |
1202e41f4b71Sopenharmony_ci
1203e41f4b71Sopenharmony_ci**错误码:**
1204e41f4b71Sopenharmony_ci
1205e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1206e41f4b71Sopenharmony_ci
1207e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1208e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1209e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1210e41f4b71Sopenharmony_ci| 17800005 | Data error.                                                  |
1211e41f4b71Sopenharmony_ci| 17800007 | Buffer error.                                                |
1212e41f4b71Sopenharmony_ci
1213e41f4b71Sopenharmony_ci**示例:**
1214e41f4b71Sopenharmony_ci
1215e41f4b71Sopenharmony_ci```ts
1216e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1217e41f4b71Sopenharmony_ci
1218e41f4b71Sopenharmony_ciasync function demo() {
1219e41f4b71Sopenharmony_ci  let str = 'hello world!';
1220e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
1221e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
1222e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
1223e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
1224e41f4b71Sopenharmony_ci  }
1225e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
1226e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
1227e41f4b71Sopenharmony_ci  await zip.compress(arrayBufferOut, arrayBufferIn, 12).then((data) => {
1228e41f4b71Sopenharmony_ci    console.info('compress success');
1229e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1230e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1231e41f4b71Sopenharmony_ci  })
1232e41f4b71Sopenharmony_ci  await zip.uncompress(arrayBufferIn, arrayBufferOut, 20).then((data) => {
1233e41f4b71Sopenharmony_ci    console.info('uncompress success');
1234e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1235e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1236e41f4b71Sopenharmony_ci  })
1237e41f4b71Sopenharmony_ci}
1238e41f4b71Sopenharmony_ci```
1239e41f4b71Sopenharmony_ci
1240e41f4b71Sopenharmony_ci### uncompress2<sup>12+</sup>
1241e41f4b71Sopenharmony_ci
1242e41f4b71Sopenharmony_ciuncompress2(dest: ArrayBuffer, source: ArrayBuffer, sourceLen?: number): Promise&lt;DecompressionOutputInfo&gt;
1243e41f4b71Sopenharmony_ci
1244e41f4b71Sopenharmony_ci将压缩后的数据解压缩为原始的未压缩形式,使用Promise异步返回。成功时返回结果状态、目标缓冲区的总大小和源数据长度。
1245e41f4b71Sopenharmony_ci
1246e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1247e41f4b71Sopenharmony_ci
1248e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1249e41f4b71Sopenharmony_ci
1250e41f4b71Sopenharmony_ci**参数:**
1251e41f4b71Sopenharmony_ci
1252e41f4b71Sopenharmony_ci| 参数名    | 类型        | 必填 | 说明           |
1253e41f4b71Sopenharmony_ci| --------- | ----------- | ---- | -------------- |
1254e41f4b71Sopenharmony_ci| dest      | ArrayBuffer | 是   | 目标缓冲区。   |
1255e41f4b71Sopenharmony_ci| source    | ArrayBuffer | 是   | 源数据缓冲区。 |
1256e41f4b71Sopenharmony_ci| sourceLen | number      | 否   | 源数据长度。   |
1257e41f4b71Sopenharmony_ci
1258e41f4b71Sopenharmony_ci**返回值:**
1259e41f4b71Sopenharmony_ci
1260e41f4b71Sopenharmony_ci| 类型                                                         | 说明                                                        |
1261e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ----------------------------------------------------------- |
1262e41f4b71Sopenharmony_ci| Promise&lt;[DecompressionOutputInfo](#decompressionoutputinfo12)&gt; | Promise对象。返回结果状态、目标缓冲区的总大小和源数据长度。 |
1263e41f4b71Sopenharmony_ci
1264e41f4b71Sopenharmony_ci**错误码:**
1265e41f4b71Sopenharmony_ci
1266e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1267e41f4b71Sopenharmony_ci
1268e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1269e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1270e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1271e41f4b71Sopenharmony_ci| 17800005 | Data error.                                                  |
1272e41f4b71Sopenharmony_ci| 17800007 | Buffer error.                                                |
1273e41f4b71Sopenharmony_ci
1274e41f4b71Sopenharmony_ci**示例:**
1275e41f4b71Sopenharmony_ci
1276e41f4b71Sopenharmony_ci```ts
1277e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1278e41f4b71Sopenharmony_ci
1279e41f4b71Sopenharmony_ciasync function demo() {
1280e41f4b71Sopenharmony_ci  let str = 'hello world!';
1281e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
1282e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
1283e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
1284e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
1285e41f4b71Sopenharmony_ci  }
1286e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
1287e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
1288e41f4b71Sopenharmony_ci  await zip.compress2(arrayBufferOut, arrayBufferIn, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
1289e41f4b71Sopenharmony_ci    console.info('compress2 success');
1290e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1291e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1292e41f4b71Sopenharmony_ci  })
1293e41f4b71Sopenharmony_ci  await zip.uncompress2(arrayBufferIn, arrayBufferOut, 20).then((data) => {
1294e41f4b71Sopenharmony_ci    console.info('uncompress2 success');
1295e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1296e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1297e41f4b71Sopenharmony_ci  })
1298e41f4b71Sopenharmony_ci}
1299e41f4b71Sopenharmony_ci```
1300e41f4b71Sopenharmony_ci
1301e41f4b71Sopenharmony_ci### compressBound<sup>12+</sup>
1302e41f4b71Sopenharmony_ci
1303e41f4b71Sopenharmony_cicompressBound(sourceLen: number): Promise&lt;number&gt;
1304e41f4b71Sopenharmony_ci
1305e41f4b71Sopenharmony_ci计算返回压缩大小的上限,使用Promise异步返回。成功时返回压缩大小的上限。
1306e41f4b71Sopenharmony_ci
1307e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1308e41f4b71Sopenharmony_ci
1309e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1310e41f4b71Sopenharmony_ci
1311e41f4b71Sopenharmony_ci**参数:**
1312e41f4b71Sopenharmony_ci
1313e41f4b71Sopenharmony_ci| 参数名    | 类型   | 必填 | 说明         |
1314e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ------------ |
1315e41f4b71Sopenharmony_ci| sourceLen | number | 是   | 源数据长度。 |
1316e41f4b71Sopenharmony_ci
1317e41f4b71Sopenharmony_ci**返回值:**
1318e41f4b71Sopenharmony_ci
1319e41f4b71Sopenharmony_ci| 类型                  | 说明                              |
1320e41f4b71Sopenharmony_ci| --------------------- | --------------------------------- |
1321e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象。返回压缩大小的上限。 |
1322e41f4b71Sopenharmony_ci
1323e41f4b71Sopenharmony_ci**错误码:**
1324e41f4b71Sopenharmony_ci
1325e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1326e41f4b71Sopenharmony_ci
1327e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1328e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1329e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1330e41f4b71Sopenharmony_ci
1331e41f4b71Sopenharmony_ci**示例:**
1332e41f4b71Sopenharmony_ci
1333e41f4b71Sopenharmony_ci```ts
1334e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1335e41f4b71Sopenharmony_ci
1336e41f4b71Sopenharmony_cilet str = 'hello world!';
1337e41f4b71Sopenharmony_cilet arrayBufferIn = new ArrayBuffer(str.length);
1338e41f4b71Sopenharmony_cilet byteArray = new Uint8Array(arrayBufferIn);
1339e41f4b71Sopenharmony_ci
1340e41f4b71Sopenharmony_cifor (let i = 0, j = str.length; i < j; i++) {
1341e41f4b71Sopenharmony_ci  byteArray[i] = str.charCodeAt(i)
1342e41f4b71Sopenharmony_ci}
1343e41f4b71Sopenharmony_ci
1344e41f4b71Sopenharmony_cilet zip = zlib.createZipSync();
1345e41f4b71Sopenharmony_ci
1346e41f4b71Sopenharmony_cizip.compressBound(str.length).then((data) => {
1347e41f4b71Sopenharmony_ci  console.info('compressBound success')
1348e41f4b71Sopenharmony_ci}).catch((errData: BusinessError) => {
1349e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1350e41f4b71Sopenharmony_ci})
1351e41f4b71Sopenharmony_ci```
1352e41f4b71Sopenharmony_ci
1353e41f4b71Sopenharmony_ci### inflateValidate<sup>12+</sup>
1354e41f4b71Sopenharmony_ci
1355e41f4b71Sopenharmony_ciinflateValidate(strm: ZStream, check: number): Promise&lt;ReturnStatus&gt;
1356e41f4b71Sopenharmony_ci
1357e41f4b71Sopenharmony_ci验证压缩流结构内部的校验和,使用Promise异步返回。成功时返回结果状态。
1358e41f4b71Sopenharmony_ci
1359e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1360e41f4b71Sopenharmony_ci
1361e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1362e41f4b71Sopenharmony_ci
1363e41f4b71Sopenharmony_ci**参数:**
1364e41f4b71Sopenharmony_ci
1365e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
1366e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
1367e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
1368e41f4b71Sopenharmony_ci| check  | number  | 是   | 预期的校验和。                  |
1369e41f4b71Sopenharmony_ci
1370e41f4b71Sopenharmony_ci**返回值:**
1371e41f4b71Sopenharmony_ci
1372e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
1373e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
1374e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
1375e41f4b71Sopenharmony_ci
1376e41f4b71Sopenharmony_ci**错误码:**
1377e41f4b71Sopenharmony_ci
1378e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1379e41f4b71Sopenharmony_ci
1380e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1381e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1382e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1383e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
1384e41f4b71Sopenharmony_ci
1385e41f4b71Sopenharmony_ci**示例:**
1386e41f4b71Sopenharmony_ci
1387e41f4b71Sopenharmony_ci```ts
1388e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1389e41f4b71Sopenharmony_ci
1390e41f4b71Sopenharmony_ciasync function demo() {
1391e41f4b71Sopenharmony_ci  let str = 'hello world!';
1392e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
1393e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
1394e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
1395e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
1396e41f4b71Sopenharmony_ci  }
1397e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
1398e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
1399e41f4b71Sopenharmony_ci  await zip.inflateInit({ nextIn: arrayBufferIn, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }
1400e41f4b71Sopenharmony_ci  ).then(data => {
1401e41f4b71Sopenharmony_ci    console.info('inflateInit success')
1402e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1403e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1404e41f4b71Sopenharmony_ci  })
1405e41f4b71Sopenharmony_ci  await zip.inflateValidate({ availableIn: 1 }, 1).then(data => {
1406e41f4b71Sopenharmony_ci    console.info('inflateValidate success')
1407e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1408e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1409e41f4b71Sopenharmony_ci  })
1410e41f4b71Sopenharmony_ci}
1411e41f4b71Sopenharmony_ci```
1412e41f4b71Sopenharmony_ci
1413e41f4b71Sopenharmony_ci### inflateSyncPoint<sup>12+</sup>
1414e41f4b71Sopenharmony_ci
1415e41f4b71Sopenharmony_ciinflateSyncPoint(strm: ZStream): Promise&lt;ReturnStatus&gt;
1416e41f4b71Sopenharmony_ci
1417e41f4b71Sopenharmony_ci查找当前解压缩流的同步点,使用Promise异步返回。成功时返回结果状态。
1418e41f4b71Sopenharmony_ci
1419e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1420e41f4b71Sopenharmony_ci
1421e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1422e41f4b71Sopenharmony_ci
1423e41f4b71Sopenharmony_ci**参数:**
1424e41f4b71Sopenharmony_ci
1425e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
1426e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
1427e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
1428e41f4b71Sopenharmony_ci
1429e41f4b71Sopenharmony_ci**返回值:**
1430e41f4b71Sopenharmony_ci
1431e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
1432e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
1433e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
1434e41f4b71Sopenharmony_ci
1435e41f4b71Sopenharmony_ci**错误码:**
1436e41f4b71Sopenharmony_ci
1437e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1438e41f4b71Sopenharmony_ci
1439e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1440e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1441e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1442e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
1443e41f4b71Sopenharmony_ci
1444e41f4b71Sopenharmony_ci**示例:**
1445e41f4b71Sopenharmony_ci
1446e41f4b71Sopenharmony_ci```ts
1447e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1448e41f4b71Sopenharmony_ci
1449e41f4b71Sopenharmony_ciasync function demo() {
1450e41f4b71Sopenharmony_ci  let str = 'hello world!';
1451e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
1452e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
1453e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
1454e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
1455e41f4b71Sopenharmony_ci  }
1456e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
1457e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
1458e41f4b71Sopenharmony_ci  await zip.inflateInit({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }
1459e41f4b71Sopenharmony_ci  ).then(data => {
1460e41f4b71Sopenharmony_ci    console.info('inflateInit success');
1461e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1462e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1463e41f4b71Sopenharmony_ci  })
1464e41f4b71Sopenharmony_ci  await zip.inflateSyncPoint({ availableIn: 1 }).then(data => {
1465e41f4b71Sopenharmony_ci    console.info('inflateSyncPoint success');
1466e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1467e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1468e41f4b71Sopenharmony_ci  })
1469e41f4b71Sopenharmony_ci}
1470e41f4b71Sopenharmony_ci```
1471e41f4b71Sopenharmony_ci
1472e41f4b71Sopenharmony_ci### inflateSync<sup>12+</sup>
1473e41f4b71Sopenharmony_ci
1474e41f4b71Sopenharmony_ciinflateSync(strm: ZStream): Promise&lt;ReturnStatus&gt;
1475e41f4b71Sopenharmony_ci
1476e41f4b71Sopenharmony_ci跳过无效的压缩数据,直到找到一个可能的完整刷新点为止,使用Promise异步返回。成功时返回结果状态。
1477e41f4b71Sopenharmony_ci
1478e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1479e41f4b71Sopenharmony_ci
1480e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1481e41f4b71Sopenharmony_ci
1482e41f4b71Sopenharmony_ci**参数:**
1483e41f4b71Sopenharmony_ci
1484e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
1485e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
1486e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
1487e41f4b71Sopenharmony_ci
1488e41f4b71Sopenharmony_ci**返回值:**
1489e41f4b71Sopenharmony_ci
1490e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
1491e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
1492e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
1493e41f4b71Sopenharmony_ci
1494e41f4b71Sopenharmony_ci**错误码:**
1495e41f4b71Sopenharmony_ci
1496e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1497e41f4b71Sopenharmony_ci
1498e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1499e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1500e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1501e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
1502e41f4b71Sopenharmony_ci| 17800005 | Data error.                                                  |
1503e41f4b71Sopenharmony_ci| 17800007 | Buffer error.                                                |
1504e41f4b71Sopenharmony_ci
1505e41f4b71Sopenharmony_ci**示例:**
1506e41f4b71Sopenharmony_ci
1507e41f4b71Sopenharmony_ci```ts
1508e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1509e41f4b71Sopenharmony_ci
1510e41f4b71Sopenharmony_ciasync function demo() {
1511e41f4b71Sopenharmony_ci  let str = 'hello, hello!';
1512e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
1513e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
1514e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
1515e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
1516e41f4b71Sopenharmony_ci  }
1517e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
1518e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
1519e41f4b71Sopenharmony_ci  await zip.deflateInit({}, zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION).then((data) => {
1520e41f4b71Sopenharmony_ci    console.info('deflateInit success')
1521e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1522e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1523e41f4b71Sopenharmony_ci  })
1524e41f4b71Sopenharmony_ci  await zip.deflate({ nextIn: arrayBufferIn, availableIn: 3, nextOut: arrayBufferOut, availableOut: 100 }, zlib.CompressFlushMode.FULL_FLUSH).then((data) => {
1525e41f4b71Sopenharmony_ci    console.info('deflate success')
1526e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1527e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1528e41f4b71Sopenharmony_ci  })
1529e41f4b71Sopenharmony_ci  await zip.deflate({ availableIn: 11 }, zlib.CompressFlushMode.FINISH).then((data) => {
1530e41f4b71Sopenharmony_ci    console.info('deflate success')
1531e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1532e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1533e41f4b71Sopenharmony_ci  })
1534e41f4b71Sopenharmony_ci  await zip.deflateEnd({}).then(data => {
1535e41f4b71Sopenharmony_ci    console.info('deflateEnd success')
1536e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1537e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1538e41f4b71Sopenharmony_ci  })
1539e41f4b71Sopenharmony_ci  try {
1540e41f4b71Sopenharmony_ci    await zip.inflateInit({ nextIn: arrayBufferOut, availableIn: 2 }).then(data => {
1541e41f4b71Sopenharmony_ci      console.info('inflateInit2 success')
1542e41f4b71Sopenharmony_ci    })
1543e41f4b71Sopenharmony_ci  } catch (errData) {
1544e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1545e41f4b71Sopenharmony_ci  }
1546e41f4b71Sopenharmony_ci  await zip.inflate({ nextOut: arrayBufferIn, availableOut: 28 }, zlib.CompressFlushMode.NO_FLUSH).then((data) => {
1547e41f4b71Sopenharmony_ci    console.info('inflate success')
1548e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1549e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1550e41f4b71Sopenharmony_ci  })
1551e41f4b71Sopenharmony_ci  await zip.inflateSync({ availableIn: 26 }).then(data => {
1552e41f4b71Sopenharmony_ci    console.info('inflateSync success');
1553e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1554e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1555e41f4b71Sopenharmony_ci  })
1556e41f4b71Sopenharmony_ci  await zip.inflateEnd({ nextOut: arrayBufferOut }).then((data) => {
1557e41f4b71Sopenharmony_ci    console.info('inflateEnd success')
1558e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1559e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1560e41f4b71Sopenharmony_ci  })
1561e41f4b71Sopenharmony_ci}
1562e41f4b71Sopenharmony_ci```
1563e41f4b71Sopenharmony_ci
1564e41f4b71Sopenharmony_ci### inflateResetKeep<sup>12+</sup>
1565e41f4b71Sopenharmony_ci
1566e41f4b71Sopenharmony_ciinflateResetKeep(strm: ZStream): Promise&lt;ReturnStatus&gt;
1567e41f4b71Sopenharmony_ci
1568e41f4b71Sopenharmony_ci重置解压缩流的状态,以保留分配的霍夫曼解码树和预设字典,使用Promise异步返回。成功时返回结果状态。
1569e41f4b71Sopenharmony_ci
1570e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1571e41f4b71Sopenharmony_ci
1572e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1573e41f4b71Sopenharmony_ci
1574e41f4b71Sopenharmony_ci**参数:**
1575e41f4b71Sopenharmony_ci
1576e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
1577e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
1578e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
1579e41f4b71Sopenharmony_ci
1580e41f4b71Sopenharmony_ci**返回值:**
1581e41f4b71Sopenharmony_ci
1582e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
1583e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
1584e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
1585e41f4b71Sopenharmony_ci
1586e41f4b71Sopenharmony_ci**错误码:**
1587e41f4b71Sopenharmony_ci
1588e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1589e41f4b71Sopenharmony_ci
1590e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1591e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1592e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1593e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
1594e41f4b71Sopenharmony_ci
1595e41f4b71Sopenharmony_ci**示例:**
1596e41f4b71Sopenharmony_ci
1597e41f4b71Sopenharmony_ci```ts
1598e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1599e41f4b71Sopenharmony_ci
1600e41f4b71Sopenharmony_ciasync function demo() {
1601e41f4b71Sopenharmony_ci  let str = 'hello world!';
1602e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
1603e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
1604e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
1605e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
1606e41f4b71Sopenharmony_ci  }
1607e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
1608e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
1609e41f4b71Sopenharmony_ci  await zip.inflateInit({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }
1610e41f4b71Sopenharmony_ci  ).then(data => {
1611e41f4b71Sopenharmony_ci    console.info('inflateInit success');
1612e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1613e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1614e41f4b71Sopenharmony_ci  })
1615e41f4b71Sopenharmony_ci  await zip.inflateResetKeep({ availableIn: 1 }).then(data => {
1616e41f4b71Sopenharmony_ci    console.info('inflateResetKeep success');
1617e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1618e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1619e41f4b71Sopenharmony_ci  })
1620e41f4b71Sopenharmony_ci}
1621e41f4b71Sopenharmony_ci```
1622e41f4b71Sopenharmony_ci
1623e41f4b71Sopenharmony_ci### inflateSetDictionary<sup>12+</sup>
1624e41f4b71Sopenharmony_ci
1625e41f4b71Sopenharmony_ciinflateSetDictionary(strm: ZStream, dictionary: ArrayBuffer): Promise&lt;ReturnStatus&gt;
1626e41f4b71Sopenharmony_ci
1627e41f4b71Sopenharmony_ci从给定的未压缩字节序列初始化解压缩字典,使用Promise异步返回。成功时返回结果状态。
1628e41f4b71Sopenharmony_ci
1629e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1630e41f4b71Sopenharmony_ci
1631e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1632e41f4b71Sopenharmony_ci
1633e41f4b71Sopenharmony_ci**参数:**
1634e41f4b71Sopenharmony_ci
1635e41f4b71Sopenharmony_ci| 参数名     | 类型        | 必填 | 说明                            |
1636e41f4b71Sopenharmony_ci| ---------- | ----------- | ---- | ------------------------------- |
1637e41f4b71Sopenharmony_ci| strm       | ZStream     | 是   | 参考[ZStream定义](#zstream12)。 |
1638e41f4b71Sopenharmony_ci| dictionary | ArrayBuffer | 是   | 字典数据。                      |
1639e41f4b71Sopenharmony_ci
1640e41f4b71Sopenharmony_ci**返回值:**
1641e41f4b71Sopenharmony_ci
1642e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
1643e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
1644e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
1645e41f4b71Sopenharmony_ci
1646e41f4b71Sopenharmony_ci**错误码:**
1647e41f4b71Sopenharmony_ci
1648e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1649e41f4b71Sopenharmony_ci
1650e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1651e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1652e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1653e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
1654e41f4b71Sopenharmony_ci| 17800005 | Data error.                                                  |
1655e41f4b71Sopenharmony_ci
1656e41f4b71Sopenharmony_ci**示例:**
1657e41f4b71Sopenharmony_ci
1658e41f4b71Sopenharmony_ci```ts
1659e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1660e41f4b71Sopenharmony_ci
1661e41f4b71Sopenharmony_ciasync function demo() {
1662e41f4b71Sopenharmony_ci  let str = 'hello, hello!';
1663e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
1664e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
1665e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
1666e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
1667e41f4b71Sopenharmony_ci  }
1668e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
1669e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
1670e41f4b71Sopenharmony_ci  let dictionary = 'hello'
1671e41f4b71Sopenharmony_ci  let dictionarybuf = new ArrayBuffer(dictionary.length);
1672e41f4b71Sopenharmony_ci  let dictionarybufdata = new Uint8Array(dictionarybuf);
1673e41f4b71Sopenharmony_ci  for (let i = 0, j = dictionary.length; i < j; i++) {
1674e41f4b71Sopenharmony_ci    dictionarybufdata[i] = str.charCodeAt(i);
1675e41f4b71Sopenharmony_ci  }
1676e41f4b71Sopenharmony_ci  await zip.deflateInit({}, zlib.CompressLevel.COMPRESS_LEVEL_BEST_COMPRESSION).then((data) => {
1677e41f4b71Sopenharmony_ci    console.info('deflateInit success')
1678e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1679e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
1680e41f4b71Sopenharmony_ci  })
1681e41f4b71Sopenharmony_ci  await zip.deflateSetDictionary({}, dictionarybuf).then((data) => {
1682e41f4b71Sopenharmony_ci    console.info('deflateSetDictionary success')
1683e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1684e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
1685e41f4b71Sopenharmony_ci  })
1686e41f4b71Sopenharmony_ci  await zip.deflate({ nextIn: arrayBufferIn, availableIn: 14, nextOut: arrayBufferOut, availableOut: 100 }, zlib.CompressFlushMode.FINISH).then((data) => {
1687e41f4b71Sopenharmony_ci    console.info('deflate success')
1688e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1689e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
1690e41f4b71Sopenharmony_ci  })
1691e41f4b71Sopenharmony_ci  await zip.deflateEnd({}).then(data => {
1692e41f4b71Sopenharmony_ci    console.info('deflateEnd success')
1693e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1694e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
1695e41f4b71Sopenharmony_ci  })
1696e41f4b71Sopenharmony_ci  try {
1697e41f4b71Sopenharmony_ci    await zip.inflateInit({ nextIn: arrayBufferOut, availableIn: 100 }).then(data => {
1698e41f4b71Sopenharmony_ci      console.info('inflateInit success')
1699e41f4b71Sopenharmony_ci    })
1700e41f4b71Sopenharmony_ci  } catch (errData) {
1701e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
1702e41f4b71Sopenharmony_ci  }
1703e41f4b71Sopenharmony_ci  await zip.inflate({ nextOut: arrayBufferIn, availableOut: 28 }, zlib.CompressFlushMode.NO_FLUSH).then((data) => {
1704e41f4b71Sopenharmony_ci    console.info('inflate success')
1705e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1706e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
1707e41f4b71Sopenharmony_ci  })
1708e41f4b71Sopenharmony_ci  await zip.inflateSetDictionary({}, dictionarybuf).then((data) => {
1709e41f4b71Sopenharmony_ci    console.info('inflateSetDictionary success')
1710e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1711e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
1712e41f4b71Sopenharmony_ci  })
1713e41f4b71Sopenharmony_ci  await zip.inflateEnd({ nextOut: arrayBufferOut }).then((data) => {
1714e41f4b71Sopenharmony_ci    console.info('inflateEnd success')
1715e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1716e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
1717e41f4b71Sopenharmony_ci  })
1718e41f4b71Sopenharmony_ci}
1719e41f4b71Sopenharmony_ci```
1720e41f4b71Sopenharmony_ci
1721e41f4b71Sopenharmony_ci### inflateReset2<sup>12+</sup>
1722e41f4b71Sopenharmony_ci
1723e41f4b71Sopenharmony_ciinflateReset2(strm: ZStream, windowBits: number): Promise&lt;ReturnStatus&gt;
1724e41f4b71Sopenharmony_ci
1725e41f4b71Sopenharmony_ci从给定的未压缩字节序列初始化解压缩字典,使用Promise异步返回。成功时返回结果状态。
1726e41f4b71Sopenharmony_ci
1727e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1728e41f4b71Sopenharmony_ci
1729e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1730e41f4b71Sopenharmony_ci
1731e41f4b71Sopenharmony_ci**参数:**
1732e41f4b71Sopenharmony_ci
1733e41f4b71Sopenharmony_ci| 参数名     | 类型    | 必填 | 说明                            |
1734e41f4b71Sopenharmony_ci| ---------- | ------- | ---- | ------------------------------- |
1735e41f4b71Sopenharmony_ci| strm       | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
1736e41f4b71Sopenharmony_ci| windowBits | number  | 是   | 最大窗口大小的以2为底的对数。   |
1737e41f4b71Sopenharmony_ci
1738e41f4b71Sopenharmony_ci**返回值:**
1739e41f4b71Sopenharmony_ci
1740e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
1741e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
1742e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
1743e41f4b71Sopenharmony_ci
1744e41f4b71Sopenharmony_ci**错误码:**
1745e41f4b71Sopenharmony_ci
1746e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1747e41f4b71Sopenharmony_ci
1748e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1749e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1750e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1751e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
1752e41f4b71Sopenharmony_ci
1753e41f4b71Sopenharmony_ci**示例:**
1754e41f4b71Sopenharmony_ci
1755e41f4b71Sopenharmony_ci```ts
1756e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1757e41f4b71Sopenharmony_ci
1758e41f4b71Sopenharmony_ciasync function demo() {
1759e41f4b71Sopenharmony_ci  let str = 'hello world!';
1760e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
1761e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
1762e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
1763e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
1764e41f4b71Sopenharmony_ci  }
1765e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
1766e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
1767e41f4b71Sopenharmony_ci  await zip.inflateInit({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }
1768e41f4b71Sopenharmony_ci  ).then(data => {
1769e41f4b71Sopenharmony_ci    console.info('inflateInit success');
1770e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1771e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1772e41f4b71Sopenharmony_ci  })
1773e41f4b71Sopenharmony_ci  await zip.inflateReset2({ availableOut: 8 }, 15).then(data => {
1774e41f4b71Sopenharmony_ci    console.info('inflateReset2 success');
1775e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1776e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1777e41f4b71Sopenharmony_ci  })
1778e41f4b71Sopenharmony_ci}
1779e41f4b71Sopenharmony_ci```
1780e41f4b71Sopenharmony_ci
1781e41f4b71Sopenharmony_ci### inflateReset<sup>12+</sup>
1782e41f4b71Sopenharmony_ci
1783e41f4b71Sopenharmony_ciinflateReset(strm: ZStream): Promise&lt;ReturnStatus&gt;
1784e41f4b71Sopenharmony_ci
1785e41f4b71Sopenharmony_ci这个函数相当于先调用inflateEnd再调用inflateInit,但是并不会释放和重新分配内部解压缩状态,使用Promise异步返回。成功时返回结果状态。
1786e41f4b71Sopenharmony_ci
1787e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1788e41f4b71Sopenharmony_ci
1789e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1790e41f4b71Sopenharmony_ci
1791e41f4b71Sopenharmony_ci**参数:**
1792e41f4b71Sopenharmony_ci
1793e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
1794e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
1795e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
1796e41f4b71Sopenharmony_ci
1797e41f4b71Sopenharmony_ci**返回值:**
1798e41f4b71Sopenharmony_ci
1799e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
1800e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
1801e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
1802e41f4b71Sopenharmony_ci
1803e41f4b71Sopenharmony_ci**错误码:**
1804e41f4b71Sopenharmony_ci
1805e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1806e41f4b71Sopenharmony_ci
1807e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1808e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1809e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1810e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
1811e41f4b71Sopenharmony_ci
1812e41f4b71Sopenharmony_ci**示例:**
1813e41f4b71Sopenharmony_ci
1814e41f4b71Sopenharmony_ci```ts
1815e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1816e41f4b71Sopenharmony_ci
1817e41f4b71Sopenharmony_ciasync function demo() {
1818e41f4b71Sopenharmony_ci  let str = 'hello world!';
1819e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
1820e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
1821e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
1822e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
1823e41f4b71Sopenharmony_ci  }
1824e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
1825e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
1826e41f4b71Sopenharmony_ci  await zip.inflateInit({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }
1827e41f4b71Sopenharmony_ci  ).then(data => {
1828e41f4b71Sopenharmony_ci    console.info('inflateInit success');
1829e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1830e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1831e41f4b71Sopenharmony_ci  })
1832e41f4b71Sopenharmony_ci  await zip.inflateReset({ availableIn: 1, availableOut: 8 }).then(data => {
1833e41f4b71Sopenharmony_ci    console.info('inflateReset success');
1834e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1835e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1836e41f4b71Sopenharmony_ci  })
1837e41f4b71Sopenharmony_ci}
1838e41f4b71Sopenharmony_ci```
1839e41f4b71Sopenharmony_ci
1840e41f4b71Sopenharmony_ci### inflatePrime<sup>12+</sup>
1841e41f4b71Sopenharmony_ci
1842e41f4b71Sopenharmony_ciinflatePrime(strm: ZStream, bits: number, value: number): Promise&lt;ReturnStatus&gt;
1843e41f4b71Sopenharmony_ci
1844e41f4b71Sopenharmony_ci从给定的未压缩字节序列初始化解压缩字典,使用Promise异步返回。成功时返回结果状态。
1845e41f4b71Sopenharmony_ci
1846e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1847e41f4b71Sopenharmony_ci
1848e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1849e41f4b71Sopenharmony_ci
1850e41f4b71Sopenharmony_ci**参数:**
1851e41f4b71Sopenharmony_ci
1852e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
1853e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
1854e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
1855e41f4b71Sopenharmony_ci| bits   | number  | 是   | 提供的位。                      |
1856e41f4b71Sopenharmony_ci| value  | number  | 是   | 提供的值。                      |
1857e41f4b71Sopenharmony_ci
1858e41f4b71Sopenharmony_ci**返回值:**
1859e41f4b71Sopenharmony_ci
1860e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
1861e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
1862e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
1863e41f4b71Sopenharmony_ci
1864e41f4b71Sopenharmony_ci**错误码:**
1865e41f4b71Sopenharmony_ci
1866e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1867e41f4b71Sopenharmony_ci
1868e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1869e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1870e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1871e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
1872e41f4b71Sopenharmony_ci
1873e41f4b71Sopenharmony_ci**示例:**
1874e41f4b71Sopenharmony_ci
1875e41f4b71Sopenharmony_ci```ts
1876e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1877e41f4b71Sopenharmony_ci
1878e41f4b71Sopenharmony_ciasync function demo() {
1879e41f4b71Sopenharmony_ci  let str = 'hello world!';
1880e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
1881e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
1882e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
1883e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
1884e41f4b71Sopenharmony_ci  }
1885e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
1886e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
1887e41f4b71Sopenharmony_ci  await zip.inflateInit({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }
1888e41f4b71Sopenharmony_ci  ).then(data => {
1889e41f4b71Sopenharmony_ci    console.info('inflateInit success');
1890e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1891e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1892e41f4b71Sopenharmony_ci  })
1893e41f4b71Sopenharmony_ci  await zip.inflatePrime({ nextOut: arrayBufferOut }, 5, 2).then(data => {
1894e41f4b71Sopenharmony_ci    console.info('inflatePrime success');
1895e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1896e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1897e41f4b71Sopenharmony_ci  })
1898e41f4b71Sopenharmony_ci}
1899e41f4b71Sopenharmony_ci```
1900e41f4b71Sopenharmony_ci
1901e41f4b71Sopenharmony_ci### inflateMark<sup>12+</sup>
1902e41f4b71Sopenharmony_ci
1903e41f4b71Sopenharmony_ciinflateMark(strm: ZStream): Promise&lt;number&gt;
1904e41f4b71Sopenharmony_ci
1905e41f4b71Sopenharmony_ci用于标记输入数据中的位置以供随机访问,使用Promise异步返回。成功时返回位置信息。
1906e41f4b71Sopenharmony_ci
1907e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1908e41f4b71Sopenharmony_ci
1909e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1910e41f4b71Sopenharmony_ci
1911e41f4b71Sopenharmony_ci**参数:**
1912e41f4b71Sopenharmony_ci
1913e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
1914e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
1915e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
1916e41f4b71Sopenharmony_ci
1917e41f4b71Sopenharmony_ci**返回值:**
1918e41f4b71Sopenharmony_ci
1919e41f4b71Sopenharmony_ci| 类型                  | 说明                        |
1920e41f4b71Sopenharmony_ci| --------------------- | --------------------------- |
1921e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象。返回位置信息。 |
1922e41f4b71Sopenharmony_ci
1923e41f4b71Sopenharmony_ci**错误码:**
1924e41f4b71Sopenharmony_ci
1925e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1926e41f4b71Sopenharmony_ci
1927e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1928e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1929e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1930e41f4b71Sopenharmony_ci
1931e41f4b71Sopenharmony_ci**示例:**
1932e41f4b71Sopenharmony_ci
1933e41f4b71Sopenharmony_ci```ts
1934e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1935e41f4b71Sopenharmony_ci
1936e41f4b71Sopenharmony_ciasync function demo() {
1937e41f4b71Sopenharmony_ci  let str = 'hello world!';
1938e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
1939e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
1940e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
1941e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
1942e41f4b71Sopenharmony_ci  }
1943e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
1944e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
1945e41f4b71Sopenharmony_ci  await zip.inflateInit({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }
1946e41f4b71Sopenharmony_ci  ).then(data => {
1947e41f4b71Sopenharmony_ci    console.info('inflateInit success');
1948e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1949e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1950e41f4b71Sopenharmony_ci  })
1951e41f4b71Sopenharmony_ci  await zip.inflateMark({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }).then(data => {
1952e41f4b71Sopenharmony_ci    console.info('inflateMark success');
1953e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
1954e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
1955e41f4b71Sopenharmony_ci  })
1956e41f4b71Sopenharmony_ci}
1957e41f4b71Sopenharmony_ci```
1958e41f4b71Sopenharmony_ci
1959e41f4b71Sopenharmony_ci### inflateInit2<sup>12+</sup>
1960e41f4b71Sopenharmony_ci
1961e41f4b71Sopenharmony_ciinflateInit2(strm: ZStream, windowBits: number): Promise&lt;ReturnStatus&gt;
1962e41f4b71Sopenharmony_ci
1963e41f4b71Sopenharmony_ci初始化内部流状态以进行解压缩,使用Promise异步返回。成功时返回结果状态。
1964e41f4b71Sopenharmony_ci
1965e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1966e41f4b71Sopenharmony_ci
1967e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
1968e41f4b71Sopenharmony_ci
1969e41f4b71Sopenharmony_ci**参数:**
1970e41f4b71Sopenharmony_ci
1971e41f4b71Sopenharmony_ci| 参数名     | 类型    | 必填 | 说明                            |
1972e41f4b71Sopenharmony_ci| ---------- | ------- | ---- | ------------------------------- |
1973e41f4b71Sopenharmony_ci| strm       | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
1974e41f4b71Sopenharmony_ci| windowBits | number  | 是   | 最大窗口大小的以2为底的对数。   |
1975e41f4b71Sopenharmony_ci
1976e41f4b71Sopenharmony_ci**返回值:**
1977e41f4b71Sopenharmony_ci
1978e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
1979e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
1980e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
1981e41f4b71Sopenharmony_ci
1982e41f4b71Sopenharmony_ci**错误码:**
1983e41f4b71Sopenharmony_ci
1984e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
1985e41f4b71Sopenharmony_ci
1986e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1987e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1988e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
1989e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
1990e41f4b71Sopenharmony_ci
1991e41f4b71Sopenharmony_ci**示例:**
1992e41f4b71Sopenharmony_ci
1993e41f4b71Sopenharmony_ci```ts
1994e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
1995e41f4b71Sopenharmony_ci
1996e41f4b71Sopenharmony_cilet str = 'hello world!';
1997e41f4b71Sopenharmony_cilet arrayBufferIn = new ArrayBuffer(str.length);
1998e41f4b71Sopenharmony_cilet byteArray = new Uint8Array(arrayBufferIn);
1999e41f4b71Sopenharmony_ci
2000e41f4b71Sopenharmony_cifor (let i = 0, j = str.length; i < j; i++) {
2001e41f4b71Sopenharmony_ci  byteArray[i] = str.charCodeAt(i)
2002e41f4b71Sopenharmony_ci}
2003e41f4b71Sopenharmony_ci
2004e41f4b71Sopenharmony_cilet arrayBufferOut = new ArrayBuffer(100);
2005e41f4b71Sopenharmony_cilet zip = zlib.createZipSync();
2006e41f4b71Sopenharmony_ci
2007e41f4b71Sopenharmony_cizip.inflateInit2({ nextIn: arrayBufferIn, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }, 28
2008e41f4b71Sopenharmony_ci).then(data => {
2009e41f4b71Sopenharmony_ci  console.info('inflateInit2 success');
2010e41f4b71Sopenharmony_ci}).catch((errData: BusinessError) => {
2011e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2012e41f4b71Sopenharmony_ci})
2013e41f4b71Sopenharmony_ci```
2014e41f4b71Sopenharmony_ci
2015e41f4b71Sopenharmony_ci### inflateInit<sup>12+</sup>
2016e41f4b71Sopenharmony_ci
2017e41f4b71Sopenharmony_ciinflateInit(strm: ZStream): Promise&lt;ReturnStatus&gt;
2018e41f4b71Sopenharmony_ci
2019e41f4b71Sopenharmony_ci初始化内部流状态以进行解压缩,使用Promise异步返回。成功时返回结果状态。
2020e41f4b71Sopenharmony_ci
2021e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2022e41f4b71Sopenharmony_ci
2023e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2024e41f4b71Sopenharmony_ci
2025e41f4b71Sopenharmony_ci**参数:**
2026e41f4b71Sopenharmony_ci
2027e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
2028e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
2029e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
2030e41f4b71Sopenharmony_ci
2031e41f4b71Sopenharmony_ci**返回值:**
2032e41f4b71Sopenharmony_ci
2033e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
2034e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
2035e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
2036e41f4b71Sopenharmony_ci
2037e41f4b71Sopenharmony_ci**错误码:**
2038e41f4b71Sopenharmony_ci
2039e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2040e41f4b71Sopenharmony_ci
2041e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2042e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2043e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2044e41f4b71Sopenharmony_ci
2045e41f4b71Sopenharmony_ci**示例:**
2046e41f4b71Sopenharmony_ci
2047e41f4b71Sopenharmony_ci```ts
2048e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
2049e41f4b71Sopenharmony_ci
2050e41f4b71Sopenharmony_cilet str = 'hello world!';
2051e41f4b71Sopenharmony_cilet arrayBufferIn = new ArrayBuffer(str.length);
2052e41f4b71Sopenharmony_cilet byteArray = new Uint8Array(arrayBufferIn);
2053e41f4b71Sopenharmony_ci
2054e41f4b71Sopenharmony_cifor (let i = 0, j = str.length; i < j; i++) {
2055e41f4b71Sopenharmony_ci  byteArray[i] = str.charCodeAt(i)
2056e41f4b71Sopenharmony_ci}
2057e41f4b71Sopenharmony_ci
2058e41f4b71Sopenharmony_cilet arrayBufferOut = new ArrayBuffer(100);
2059e41f4b71Sopenharmony_cilet zip = zlib.createZipSync();
2060e41f4b71Sopenharmony_ci
2061e41f4b71Sopenharmony_cizip.inflateInit({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }
2062e41f4b71Sopenharmony_ci).then(data => {
2063e41f4b71Sopenharmony_ci  console.info('inflateInit success');
2064e41f4b71Sopenharmony_ci}).catch((errData: BusinessError) => {
2065e41f4b71Sopenharmony_ci  console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2066e41f4b71Sopenharmony_ci})
2067e41f4b71Sopenharmony_ci```
2068e41f4b71Sopenharmony_ci
2069e41f4b71Sopenharmony_ci### inflateGetHeader<sup>12+</sup>
2070e41f4b71Sopenharmony_ci
2071e41f4b71Sopenharmony_ciinflateGetHeader(strm: ZStream, header: GzHeader): Promise&lt;ReturnStatus&gt;
2072e41f4b71Sopenharmony_ci
2073e41f4b71Sopenharmony_ci用于在解压缩数据前设置gzip文件头部信息,使用Promise异步返回。成功时返回结果状态。
2074e41f4b71Sopenharmony_ci
2075e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2076e41f4b71Sopenharmony_ci
2077e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2078e41f4b71Sopenharmony_ci
2079e41f4b71Sopenharmony_ci**参数:**
2080e41f4b71Sopenharmony_ci
2081e41f4b71Sopenharmony_ci| 参数名 | 类型                    | 必填 | 说明                             |
2082e41f4b71Sopenharmony_ci| ------ | ----------------------- | ---- | -------------------------------- |
2083e41f4b71Sopenharmony_ci| strm   | ZStream                 | 是   | 参考[ZStream定义](#zstream12)。  |
2084e41f4b71Sopenharmony_ci| header | [GzHeader](#gzheader12) | 是   | 从压缩数据流中提取的gzip头信息。 |
2085e41f4b71Sopenharmony_ci
2086e41f4b71Sopenharmony_ci**返回值:**
2087e41f4b71Sopenharmony_ci
2088e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
2089e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
2090e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
2091e41f4b71Sopenharmony_ci
2092e41f4b71Sopenharmony_ci**错误码:**
2093e41f4b71Sopenharmony_ci
2094e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
2095e41f4b71Sopenharmony_ci
2096e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2097e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2098e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2099e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
2100e41f4b71Sopenharmony_ci
2101e41f4b71Sopenharmony_ci**示例:**
2102e41f4b71Sopenharmony_ci
2103e41f4b71Sopenharmony_ci```ts
2104e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
2105e41f4b71Sopenharmony_ci
2106e41f4b71Sopenharmony_ciasync function demo() {
2107e41f4b71Sopenharmony_ci  let str = 'hello world!';
2108e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
2109e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
2110e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
2111e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
2112e41f4b71Sopenharmony_ci  }
2113e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
2114e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
2115e41f4b71Sopenharmony_ci  await zip.inflateInit2({ nextIn: arrayBufferIn, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }, 28
2116e41f4b71Sopenharmony_ci  ).then(data => {
2117e41f4b71Sopenharmony_ci    console.info('inflateInit2 success');
2118e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2119e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2120e41f4b71Sopenharmony_ci  })
2121e41f4b71Sopenharmony_ci  await zip.inflateGetHeader({ availableIn: 1, availableOut: 1 }, { isText: true, os: 1, time: 1, xflags: 1, extra: arrayBufferIn, extraLen: 12, name: arrayBufferIn, comment: arrayBufferOut, hcrc: true, done: true }).then(data => {
2122e41f4b71Sopenharmony_ci    console.info('inflateGetHeader success');
2123e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2124e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2125e41f4b71Sopenharmony_ci  })
2126e41f4b71Sopenharmony_ci}
2127e41f4b71Sopenharmony_ci```
2128e41f4b71Sopenharmony_ci
2129e41f4b71Sopenharmony_ci### inflateGetDictionary<sup>12+</sup>
2130e41f4b71Sopenharmony_ci
2131e41f4b71Sopenharmony_ciinflateGetDictionary(strm: ZStream, dictionary: ArrayBuffer): Promise&lt;DictionaryOutputInfo&gt;
2132e41f4b71Sopenharmony_ci
2133e41f4b71Sopenharmony_ci获取当前解压缩流中使用的解压缩字典内容及其长度,使用Promise异步返回。成功时返回结果状态和字典的长度。
2134e41f4b71Sopenharmony_ci
2135e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2136e41f4b71Sopenharmony_ci
2137e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2138e41f4b71Sopenharmony_ci
2139e41f4b71Sopenharmony_ci**参数:**
2140e41f4b71Sopenharmony_ci
2141e41f4b71Sopenharmony_ci| 参数名     | 类型        | 必填 | 说明                            |
2142e41f4b71Sopenharmony_ci| ---------- | ----------- | ---- | ------------------------------- |
2143e41f4b71Sopenharmony_ci| strm       | ZStream     | 是   | 参考[ZStream定义](#zstream12)。 |
2144e41f4b71Sopenharmony_ci| dictionary | ArrayBuffer | 是   | 接收解压缩字典的实际内容。      |
2145e41f4b71Sopenharmony_ci
2146e41f4b71Sopenharmony_ci**返回值:**
2147e41f4b71Sopenharmony_ci
2148e41f4b71Sopenharmony_ci| 类型                                                         | 说明                                    |
2149e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | --------------------------------------- |
2150e41f4b71Sopenharmony_ci| Promise&lt;[DictionaryOutputInfo](#dictionaryoutputinfo12)&gt; | Promise对象。返回结果状态和字典的长度。 |
2151e41f4b71Sopenharmony_ci
2152e41f4b71Sopenharmony_ci**错误码:**
2153e41f4b71Sopenharmony_ci
2154e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
2155e41f4b71Sopenharmony_ci
2156e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2157e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2158e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2159e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
2160e41f4b71Sopenharmony_ci
2161e41f4b71Sopenharmony_ci**示例:**
2162e41f4b71Sopenharmony_ci
2163e41f4b71Sopenharmony_ci```ts
2164e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
2165e41f4b71Sopenharmony_ci
2166e41f4b71Sopenharmony_ciasync function demo() {
2167e41f4b71Sopenharmony_ci  let str = 'hello world!';
2168e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
2169e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
2170e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
2171e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
2172e41f4b71Sopenharmony_ci  }
2173e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
2174e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
2175e41f4b71Sopenharmony_ci  await zip.inflateInit2({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }, 28
2176e41f4b71Sopenharmony_ci  ).then(data => {
2177e41f4b71Sopenharmony_ci    console.info('inflateInit2 success');
2178e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2179e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2180e41f4b71Sopenharmony_ci  })
2181e41f4b71Sopenharmony_ci  await zip.inflateGetDictionary({ nextOut: arrayBufferOut }, arrayBufferOut).then((data) => {
2182e41f4b71Sopenharmony_ci    console.info('inflateGetDictionary success:')
2183e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2184e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2185e41f4b71Sopenharmony_ci  })
2186e41f4b71Sopenharmony_ci}
2187e41f4b71Sopenharmony_ci```
2188e41f4b71Sopenharmony_ci
2189e41f4b71Sopenharmony_ci### inflateEnd<sup>12+</sup>
2190e41f4b71Sopenharmony_ci
2191e41f4b71Sopenharmony_ciinflateEnd(strm: ZStream): Promise&lt;ReturnStatus&gt;
2192e41f4b71Sopenharmony_ci
2193e41f4b71Sopenharmony_ci解压流的所有动态分配的数据结构都被释放,使用Promise异步返回。成功时返回结果状态。
2194e41f4b71Sopenharmony_ci
2195e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2196e41f4b71Sopenharmony_ci
2197e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2198e41f4b71Sopenharmony_ci
2199e41f4b71Sopenharmony_ci**参数:**
2200e41f4b71Sopenharmony_ci
2201e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
2202e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
2203e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
2204e41f4b71Sopenharmony_ci
2205e41f4b71Sopenharmony_ci**返回值:**
2206e41f4b71Sopenharmony_ci
2207e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
2208e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
2209e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
2210e41f4b71Sopenharmony_ci
2211e41f4b71Sopenharmony_ci**错误码:**
2212e41f4b71Sopenharmony_ci
2213e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
2214e41f4b71Sopenharmony_ci
2215e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2216e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2217e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2218e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
2219e41f4b71Sopenharmony_ci
2220e41f4b71Sopenharmony_ci**示例:**
2221e41f4b71Sopenharmony_ci
2222e41f4b71Sopenharmony_ci```ts
2223e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
2224e41f4b71Sopenharmony_ci
2225e41f4b71Sopenharmony_ciasync function demo() {
2226e41f4b71Sopenharmony_ci  let str = 'hello world!';
2227e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
2228e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
2229e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
2230e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
2231e41f4b71Sopenharmony_ci  }
2232e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
2233e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
2234e41f4b71Sopenharmony_ci  await zip.inflateInit({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }
2235e41f4b71Sopenharmony_ci  ).then(data => {
2236e41f4b71Sopenharmony_ci    console.info('inflateInit success');
2237e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2238e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2239e41f4b71Sopenharmony_ci  })
2240e41f4b71Sopenharmony_ci  await zip.inflate({ availableIn: 8, availableOut: 8 }, 0).then((data) => {
2241e41f4b71Sopenharmony_ci    console.info('inflate success')
2242e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2243e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2244e41f4b71Sopenharmony_ci  })
2245e41f4b71Sopenharmony_ci  await zip.inflateEnd({ nextOut: arrayBufferOut }).then((data) => {
2246e41f4b71Sopenharmony_ci    console.info('inflateEnd success')
2247e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2248e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2249e41f4b71Sopenharmony_ci  })
2250e41f4b71Sopenharmony_ci}
2251e41f4b71Sopenharmony_ci```
2252e41f4b71Sopenharmony_ci
2253e41f4b71Sopenharmony_ci### inflateCopy<sup>12+</sup>
2254e41f4b71Sopenharmony_ci
2255e41f4b71Sopenharmony_ciinflateCopy(source: Zip): Promise&lt;ReturnStatus&gt;
2256e41f4b71Sopenharmony_ci
2257e41f4b71Sopenharmony_ci复制解压流,使用Promise异步返回。成功时返回结果状态。
2258e41f4b71Sopenharmony_ci
2259e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2260e41f4b71Sopenharmony_ci
2261e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2262e41f4b71Sopenharmony_ci
2263e41f4b71Sopenharmony_ci**参数:**
2264e41f4b71Sopenharmony_ci
2265e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明                    |
2266e41f4b71Sopenharmony_ci| ------ | ---- | ---- | ----------------------- |
2267e41f4b71Sopenharmony_ci| source | Zip  | 是   | 参考[Zip定义](#zip12)。 |
2268e41f4b71Sopenharmony_ci
2269e41f4b71Sopenharmony_ci**返回值:**
2270e41f4b71Sopenharmony_ci
2271e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
2272e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
2273e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
2274e41f4b71Sopenharmony_ci
2275e41f4b71Sopenharmony_ci**错误码:**
2276e41f4b71Sopenharmony_ci
2277e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
2278e41f4b71Sopenharmony_ci
2279e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2280e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2281e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2282e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
2283e41f4b71Sopenharmony_ci
2284e41f4b71Sopenharmony_ci**示例:**
2285e41f4b71Sopenharmony_ci
2286e41f4b71Sopenharmony_ci```ts
2287e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
2288e41f4b71Sopenharmony_ci
2289e41f4b71Sopenharmony_ciasync function demo() {
2290e41f4b71Sopenharmony_ci  let str = 'hello world!';
2291e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
2292e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
2293e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
2294e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
2295e41f4b71Sopenharmony_ci  }
2296e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
2297e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
2298e41f4b71Sopenharmony_ci  await zip.inflateInit({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }
2299e41f4b71Sopenharmony_ci  ).then(data => {
2300e41f4b71Sopenharmony_ci    console.info('inflateInit success');
2301e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2302e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2303e41f4b71Sopenharmony_ci  })
2304e41f4b71Sopenharmony_ci  await zip.inflateCopy(zip).then((data) => {
2305e41f4b71Sopenharmony_ci    console.info('inflateCopy success')
2306e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2307e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2308e41f4b71Sopenharmony_ci  })
2309e41f4b71Sopenharmony_ci}
2310e41f4b71Sopenharmony_ci```
2311e41f4b71Sopenharmony_ci
2312e41f4b71Sopenharmony_ci### inflateCodesUsed<sup>12+</sup>
2313e41f4b71Sopenharmony_ci
2314e41f4b71Sopenharmony_ciinflateCodesUsed(strm: ZStream): Promise&lt;number&gt;
2315e41f4b71Sopenharmony_ci
2316e41f4b71Sopenharmony_ci当前解压缩流中使用的霍夫曼编码树的数量,使用Promise异步返回。成功时返回已使用的霍夫曼编码树的数量。
2317e41f4b71Sopenharmony_ci
2318e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2319e41f4b71Sopenharmony_ci
2320e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2321e41f4b71Sopenharmony_ci
2322e41f4b71Sopenharmony_ci**参数:**
2323e41f4b71Sopenharmony_ci
2324e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
2325e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
2326e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
2327e41f4b71Sopenharmony_ci
2328e41f4b71Sopenharmony_ci**返回值:**
2329e41f4b71Sopenharmony_ci
2330e41f4b71Sopenharmony_ci| 类型                  | 说明                                          |
2331e41f4b71Sopenharmony_ci| --------------------- | --------------------------------------------- |
2332e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象。返回已使用的霍夫曼编码树的数量。 |
2333e41f4b71Sopenharmony_ci
2334e41f4b71Sopenharmony_ci**错误码:**
2335e41f4b71Sopenharmony_ci
2336e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2337e41f4b71Sopenharmony_ci
2338e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2339e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2340e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2341e41f4b71Sopenharmony_ci
2342e41f4b71Sopenharmony_ci**示例:**
2343e41f4b71Sopenharmony_ci
2344e41f4b71Sopenharmony_ci```ts
2345e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
2346e41f4b71Sopenharmony_ci
2347e41f4b71Sopenharmony_ciasync function demo() {
2348e41f4b71Sopenharmony_ci  let str = 'hello world!';
2349e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
2350e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
2351e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
2352e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
2353e41f4b71Sopenharmony_ci  }
2354e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
2355e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
2356e41f4b71Sopenharmony_ci  await zip.inflateInit({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }
2357e41f4b71Sopenharmony_ci  ).then(data => {
2358e41f4b71Sopenharmony_ci    console.info('inflateInit success');
2359e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2360e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2361e41f4b71Sopenharmony_ci  })
2362e41f4b71Sopenharmony_ci  await zip.inflateCodesUsed({ nextIn: arrayBufferIn, availableIn: 1, nextOut: arrayBufferOut, availableOut: 8 }).then(data => {
2363e41f4b71Sopenharmony_ci    console.info('inflateCodesUsed success');
2364e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2365e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2366e41f4b71Sopenharmony_ci  })
2367e41f4b71Sopenharmony_ci}
2368e41f4b71Sopenharmony_ci```
2369e41f4b71Sopenharmony_ci
2370e41f4b71Sopenharmony_ci### inflateBackInit<sup>12+</sup>
2371e41f4b71Sopenharmony_ci
2372e41f4b71Sopenharmony_ciinflateBackInit(strm: ZStream, windowBits: number, window: ArrayBuffer): Promise&lt;ReturnStatus&gt;
2373e41f4b71Sopenharmony_ci
2374e41f4b71Sopenharmony_ci使用inflateBack()函数前初始化内部流状态以进行解压缩,使用Promise异步返回。成功时返回结果状态。
2375e41f4b71Sopenharmony_ci
2376e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2377e41f4b71Sopenharmony_ci
2378e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2379e41f4b71Sopenharmony_ci
2380e41f4b71Sopenharmony_ci**参数:**
2381e41f4b71Sopenharmony_ci
2382e41f4b71Sopenharmony_ci| 参数名     | 类型        | 必填 | 说明                                          |
2383e41f4b71Sopenharmony_ci| ---------- | ----------- | ---- | --------------------------------------------- |
2384e41f4b71Sopenharmony_ci| strm       | ZStream     | 是   | 参考[ZStream定义](#zstream12)。               |
2385e41f4b71Sopenharmony_ci| windowBits | number      | 是   | 最大窗口大小的以2为底的对数,取值范围在8~15。 |
2386e41f4b71Sopenharmony_ci| window     | ArrayBuffer | 是   | 预设的窗口缓冲区。                            |
2387e41f4b71Sopenharmony_ci
2388e41f4b71Sopenharmony_ci**返回值:**
2389e41f4b71Sopenharmony_ci
2390e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
2391e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
2392e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
2393e41f4b71Sopenharmony_ci
2394e41f4b71Sopenharmony_ci**错误码:**
2395e41f4b71Sopenharmony_ci
2396e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
2397e41f4b71Sopenharmony_ci
2398e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2399e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2400e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2401e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
2402e41f4b71Sopenharmony_ci
2403e41f4b71Sopenharmony_ci**示例:**参考[inflateBack](#inflateback12)
2404e41f4b71Sopenharmony_ci
2405e41f4b71Sopenharmony_ci### inflateBackEnd<sup>12+</sup>
2406e41f4b71Sopenharmony_ci
2407e41f4b71Sopenharmony_ciinflateBackEnd(strm: ZStream): Promise&lt;ReturnStatus&gt;
2408e41f4b71Sopenharmony_ci
2409e41f4b71Sopenharmony_ciinflateBackInit()函数分配的所有内存都被释放,使用Promise异步返回。成功时返回结果状态。
2410e41f4b71Sopenharmony_ci
2411e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2412e41f4b71Sopenharmony_ci
2413e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2414e41f4b71Sopenharmony_ci
2415e41f4b71Sopenharmony_ci**参数:**
2416e41f4b71Sopenharmony_ci
2417e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
2418e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
2419e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
2420e41f4b71Sopenharmony_ci
2421e41f4b71Sopenharmony_ci**返回值:**
2422e41f4b71Sopenharmony_ci
2423e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
2424e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
2425e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
2426e41f4b71Sopenharmony_ci
2427e41f4b71Sopenharmony_ci**错误码:**
2428e41f4b71Sopenharmony_ci
2429e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
2430e41f4b71Sopenharmony_ci
2431e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2432e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2433e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2434e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
2435e41f4b71Sopenharmony_ci
2436e41f4b71Sopenharmony_ci**示例:**参考[inflateBack](#inflateback12)
2437e41f4b71Sopenharmony_ci
2438e41f4b71Sopenharmony_ci### inflateBack<sup>12+</sup>
2439e41f4b71Sopenharmony_ci
2440e41f4b71Sopenharmony_ciinflateBack(strm: ZStream, backIn: InflateBackInputCallback, inDesc: object, backOut: InflateBackOutputCallback, outDesc: object): Promise&lt;ReturnStatus&gt;
2441e41f4b71Sopenharmony_ci
2442e41f4b71Sopenharmony_ci实现原始解压缩,采用回调接口来处理输入和输出,使用Promise异步返回。成功时返回结果状态。
2443e41f4b71Sopenharmony_ci
2444e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2445e41f4b71Sopenharmony_ci
2446e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2447e41f4b71Sopenharmony_ci
2448e41f4b71Sopenharmony_ci**参数:**
2449e41f4b71Sopenharmony_ci
2450e41f4b71Sopenharmony_ci| 参数名  | 类型                      | 必填 | 说明                                                         |
2451e41f4b71Sopenharmony_ci| ------- | ------------------------- | ---- | ------------------------------------------------------------ |
2452e41f4b71Sopenharmony_ci| strm    | ZStream                   | 是   | 参考[ZStream定义](#zstream12)。                              |
2453e41f4b71Sopenharmony_ci| backIn  | InflateBackInputCallback  | 是   | 一种函数,用于从末尾解压缩数据,以从输入源读取原始压缩数据。 |
2454e41f4b71Sopenharmony_ci| inDesc  | object                    | 是   | 通用对象。                                                   |
2455e41f4b71Sopenharmony_ci| backOut | InflateBackOutputCallback | 是   | 将解压缩的数据写入目标输出。                                 |
2456e41f4b71Sopenharmony_ci| outDesc | object                    | 是   | 通用对象。                                                   |
2457e41f4b71Sopenharmony_ci
2458e41f4b71Sopenharmony_ciInflateBackInputCallback的说明:
2459e41f4b71Sopenharmony_ci
2460e41f4b71Sopenharmony_ciInflateBackInputCallback = (inDesc: object) => ArrayBuffer
2461e41f4b71Sopenharmony_ci
2462e41f4b71Sopenharmony_ci| 名称   | 类型   | 必填 | 说明             |
2463e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------- |
2464e41f4b71Sopenharmony_ci| inDesc | object | 是   | 用户定义数据对象 |
2465e41f4b71Sopenharmony_ci
2466e41f4b71Sopenharmony_ciInflateBackOutputCallback的说明:
2467e41f4b71Sopenharmony_ci
2468e41f4b71Sopenharmony_ciInflateBackOutputCallback = (outDesc: object, buf: ArrayBuffer, length: number) => number
2469e41f4b71Sopenharmony_ci
2470e41f4b71Sopenharmony_ci| 名称    | 类型        | 必填 | 说明                   |
2471e41f4b71Sopenharmony_ci| ------- | ----------- | ---- | ---------------------- |
2472e41f4b71Sopenharmony_ci| outDesc | object      | 是   | 用户定义数据对象       |
2473e41f4b71Sopenharmony_ci| buf     | ArrayBuffer | 是   | 用于存储要写入的数据。 |
2474e41f4b71Sopenharmony_ci| length  | number      | 是   | 写入输出缓冲区的长度。 |
2475e41f4b71Sopenharmony_ci
2476e41f4b71Sopenharmony_ci**返回值:**
2477e41f4b71Sopenharmony_ci
2478e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
2479e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
2480e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
2481e41f4b71Sopenharmony_ci
2482e41f4b71Sopenharmony_ci**错误码:**
2483e41f4b71Sopenharmony_ci
2484e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
2485e41f4b71Sopenharmony_ci
2486e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2487e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2488e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2489e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
2490e41f4b71Sopenharmony_ci
2491e41f4b71Sopenharmony_ci**示例:**
2492e41f4b71Sopenharmony_ci
2493e41f4b71Sopenharmony_ci```ts
2494e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
2495e41f4b71Sopenharmony_ci
2496e41f4b71Sopenharmony_ciasync function demo() {
2497e41f4b71Sopenharmony_ci  let readIn: (inDesc: object) => ArrayBuffer = (inDesc: object): ArrayBuffer => {
2498e41f4b71Sopenharmony_ci    console.info("inDesc = ", JSON.stringify(inDesc));
2499e41f4b71Sopenharmony_ci    let buffer = new ArrayBuffer(26)
2500e41f4b71Sopenharmony_ci    let array = new Uint8Array(buffer);
2501e41f4b71Sopenharmony_ci    array.set([31, 139, 8, 0, 0, 0, 0, 0, 0, 10, 243, 72, 205, 201, 201, 231, 2, 0, 22, 53, 150, 49, 6, 0, 0, 0]);
2502e41f4b71Sopenharmony_ci    return buffer;
2503e41f4b71Sopenharmony_ci  }
2504e41f4b71Sopenharmony_ci
2505e41f4b71Sopenharmony_ci  let writeOut: (outDesc: object, buffer: ArrayBuffer, length: number) => number = (outDesc: object, buffer: ArrayBuffer, length: number): number => {
2506e41f4b71Sopenharmony_ci    console.info("outDesc = ", outDesc);
2507e41f4b71Sopenharmony_ci    console.info("buffer = ", buffer);
2508e41f4b71Sopenharmony_ci    console.info("length = ", length);
2509e41f4b71Sopenharmony_ci    let array = new Uint8Array(buffer);
2510e41f4b71Sopenharmony_ci    let dataString = "";
2511e41f4b71Sopenharmony_ci    for (let i = 0; i < length; i++) {
2512e41f4b71Sopenharmony_ci      dataString += String.fromCharCode(array[i]);
2513e41f4b71Sopenharmony_ci    }
2514e41f4b71Sopenharmony_ci    console.info('writeOut ', dataString);
2515e41f4b71Sopenharmony_ci    return 0;
2516e41f4b71Sopenharmony_ci  }
2517e41f4b71Sopenharmony_ci
2518e41f4b71Sopenharmony_ci  let have = 0;
2519e41f4b71Sopenharmony_ci  let first = 1;
2520e41f4b71Sopenharmony_ci  let arrayBuffer = new ArrayBuffer(26);
2521e41f4b71Sopenharmony_ci  let next = new Uint8Array(arrayBuffer);
2522e41f4b71Sopenharmony_ci  let last = 0;
2523e41f4b71Sopenharmony_ci  let index = 0;
2524e41f4b71Sopenharmony_ci  let flags = 0;
2525e41f4b71Sopenharmony_ci  let NEXT2: () => number = (): number => {
2526e41f4b71Sopenharmony_ci    let o6: object = new Object()
2527e41f4b71Sopenharmony_ci    if (!have) {
2528e41f4b71Sopenharmony_ci      arrayBuffer = readIn(o6)
2529e41f4b71Sopenharmony_ci      next = new Uint8Array(arrayBuffer);
2530e41f4b71Sopenharmony_ci      console.info('readIn next = ', next.length)
2531e41f4b71Sopenharmony_ci      have = next.length;
2532e41f4b71Sopenharmony_ci    }
2533e41f4b71Sopenharmony_ci    if (have) {
2534e41f4b71Sopenharmony_ci      have--;
2535e41f4b71Sopenharmony_ci      last = next[index];
2536e41f4b71Sopenharmony_ci      index++;
2537e41f4b71Sopenharmony_ci    }
2538e41f4b71Sopenharmony_ci    else {
2539e41f4b71Sopenharmony_ci      last = -1;
2540e41f4b71Sopenharmony_ci    }
2541e41f4b71Sopenharmony_ci    return last;
2542e41f4b71Sopenharmony_ci  }
2543e41f4b71Sopenharmony_ci
2544e41f4b71Sopenharmony_ci  let inflateBackTest: () => void = (async () => {
2545e41f4b71Sopenharmony_ci    try {
2546e41f4b71Sopenharmony_ci      have = 0;
2547e41f4b71Sopenharmony_ci      first = 1;
2548e41f4b71Sopenharmony_ci      arrayBuffer = new ArrayBuffer(26);
2549e41f4b71Sopenharmony_ci      next = new Uint8Array(arrayBuffer);
2550e41f4b71Sopenharmony_ci      last = 0;
2551e41f4b71Sopenharmony_ci      index = 0;
2552e41f4b71Sopenharmony_ci      flags = 0;
2553e41f4b71Sopenharmony_ci      let sr = zlib.createZipSync();
2554e41f4b71Sopenharmony_ci      let buffer = new ArrayBuffer(1024)
2555e41f4b71Sopenharmony_ci      await sr.inflateBackInit({}, 15, buffer).then((result) => {
2556e41f4b71Sopenharmony_ci        console.info('inflateBackInit Call result res', result)
2557e41f4b71Sopenharmony_ci      })
2558e41f4b71Sopenharmony_ci      let ret = 0;
2559e41f4b71Sopenharmony_ci      for (; ;) {
2560e41f4b71Sopenharmony_ci        if (NEXT2() == -1) {
2561e41f4b71Sopenharmony_ci          ret = 0;
2562e41f4b71Sopenharmony_ci          console.info('inflateBackTest Call result NEXT2() == -1')
2563e41f4b71Sopenharmony_ci          break;
2564e41f4b71Sopenharmony_ci        }
2565e41f4b71Sopenharmony_ci        console.info('have =  last = ', have, last)
2566e41f4b71Sopenharmony_ci        if (last != 31 || (NEXT2() != 139 && last >= 157 && last <= 157)) {
2567e41f4b71Sopenharmony_ci          ret = first ? -3 : -1;
2568e41f4b71Sopenharmony_ci          console.info('inflateBackTest Call result last != 31 || (NEXT2() != 139 && last != 157)')
2569e41f4b71Sopenharmony_ci          break;
2570e41f4b71Sopenharmony_ci        }
2571e41f4b71Sopenharmony_ci        first = 0;
2572e41f4b71Sopenharmony_ci        ret = -5;
2573e41f4b71Sopenharmony_ci        if (NEXT2() != 8) {
2574e41f4b71Sopenharmony_ci          if (last < 0) {
2575e41f4b71Sopenharmony_ci            console.info('inflateBackTest Call result 1 last == -1')
2576e41f4b71Sopenharmony_ci            break;
2577e41f4b71Sopenharmony_ci          }
2578e41f4b71Sopenharmony_ci        }
2579e41f4b71Sopenharmony_ci        flags = NEXT2();
2580e41f4b71Sopenharmony_ci        NEXT2();
2581e41f4b71Sopenharmony_ci        NEXT2();
2582e41f4b71Sopenharmony_ci        NEXT2();
2583e41f4b71Sopenharmony_ci        NEXT2();
2584e41f4b71Sopenharmony_ci        NEXT2();
2585e41f4b71Sopenharmony_ci        NEXT2();
2586e41f4b71Sopenharmony_ci        if (last < 0) {
2587e41f4b71Sopenharmony_ci          console.info('inflateBackTest Call result 2 last == -1')
2588e41f4b71Sopenharmony_ci          break;
2589e41f4b71Sopenharmony_ci        }
2590e41f4b71Sopenharmony_ci        console.info('index =  have = ', next[index], have)
2591e41f4b71Sopenharmony_ci        let newArrayBuffer = new ArrayBuffer(have);
2592e41f4b71Sopenharmony_ci        let newNext = new Uint8Array(newArrayBuffer);
2593e41f4b71Sopenharmony_ci        for (let i = 0; i < have; i++) {
2594e41f4b71Sopenharmony_ci          newNext[i] = next[26 - have + i];
2595e41f4b71Sopenharmony_ci        }
2596e41f4b71Sopenharmony_ci        console.info('newArrayBuffer.length = ', newArrayBuffer.byteLength)
2597e41f4b71Sopenharmony_ci        console.info('newNext.length = ', newNext.length)
2598e41f4b71Sopenharmony_ci        let zStream: zlib.ZStream = {
2599e41f4b71Sopenharmony_ci          nextIn: newArrayBuffer,
2600e41f4b71Sopenharmony_ci          availableIn: have,
2601e41f4b71Sopenharmony_ci        };
2602e41f4b71Sopenharmony_ci        await sr.inflateBack(
2603e41f4b71Sopenharmony_ci          zStream,
2604e41f4b71Sopenharmony_ci          readIn,
2605e41f4b71Sopenharmony_ci          { fileName: 'test.gz' },
2606e41f4b71Sopenharmony_ci          writeOut,
2607e41f4b71Sopenharmony_ci          { fileName: 'test.gz' }).then((result) => {
2608e41f4b71Sopenharmony_ci            ret = result;
2609e41f4b71Sopenharmony_ci            console.info('inflateBack Call result res', result)
2610e41f4b71Sopenharmony_ci          })
2611e41f4b71Sopenharmony_ci        if (ret == 1) {
2612e41f4b71Sopenharmony_ci          console.info('inflateBackTest Call result success')
2613e41f4b71Sopenharmony_ci          break;
2614e41f4b71Sopenharmony_ci        }
2615e41f4b71Sopenharmony_ci      }
2616e41f4b71Sopenharmony_ci      await sr.inflateBackEnd({}).then((result) => {
2617e41f4b71Sopenharmony_ci        console.info('inflateBackEnd Call result res', result)
2618e41f4b71Sopenharmony_ci      })
2619e41f4b71Sopenharmony_ci    }
2620e41f4b71Sopenharmony_ci    catch (errData) {
2621e41f4b71Sopenharmony_ci      console.error(`errData is message:${errData}`);
2622e41f4b71Sopenharmony_ci    }
2623e41f4b71Sopenharmony_ci  })
2624e41f4b71Sopenharmony_ci  inflateBackTest();
2625e41f4b71Sopenharmony_ci}
2626e41f4b71Sopenharmony_ci```
2627e41f4b71Sopenharmony_ci
2628e41f4b71Sopenharmony_ci### inflate<sup>12+</sup>
2629e41f4b71Sopenharmony_ci
2630e41f4b71Sopenharmony_ciinflate(strm: ZStream, flush: CompressFlushMode): Promise&lt;ReturnStatus&gt;
2631e41f4b71Sopenharmony_ci
2632e41f4b71Sopenharmony_ci解压数据,使用Promise异步返回。成功时返回结果状态。
2633e41f4b71Sopenharmony_ci
2634e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2635e41f4b71Sopenharmony_ci
2636e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2637e41f4b71Sopenharmony_ci
2638e41f4b71Sopenharmony_ci**参数:**
2639e41f4b71Sopenharmony_ci
2640e41f4b71Sopenharmony_ci| 参数名 | 类型              | 必填 | 说明                                                   |
2641e41f4b71Sopenharmony_ci| ------ | ----------------- | ---- | ------------------------------------------------------ |
2642e41f4b71Sopenharmony_ci| strm   | ZStream           | 是   | 参考[ZStream定义](#zstream12)。                        |
2643e41f4b71Sopenharmony_ci| flush  | CompressFlushMode | 是   | 参考[CompressFlushMode定义](#zipcompressflushmode12)。 |
2644e41f4b71Sopenharmony_ci
2645e41f4b71Sopenharmony_ci**返回值:**
2646e41f4b71Sopenharmony_ci
2647e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
2648e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
2649e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
2650e41f4b71Sopenharmony_ci
2651e41f4b71Sopenharmony_ci**错误码:**
2652e41f4b71Sopenharmony_ci
2653e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
2654e41f4b71Sopenharmony_ci
2655e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2656e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2657e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2658e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
2659e41f4b71Sopenharmony_ci| 17800005 | Data error.                                                  |
2660e41f4b71Sopenharmony_ci
2661e41f4b71Sopenharmony_ci**示例:**
2662e41f4b71Sopenharmony_ci
2663e41f4b71Sopenharmony_ci```ts
2664e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
2665e41f4b71Sopenharmony_ci
2666e41f4b71Sopenharmony_ciasync function demo() {
2667e41f4b71Sopenharmony_ci  let str = 'hello world!';
2668e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
2669e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
2670e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
2671e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
2672e41f4b71Sopenharmony_ci  }
2673e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
2674e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
2675e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
2676e41f4b71Sopenharmony_ci    availableIn: 1,
2677e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
2678e41f4b71Sopenharmony_ci    availableOut: 1
2679e41f4b71Sopenharmony_ci  };
2680e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
2681e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
2682e41f4b71Sopenharmony_ci    console.info('deflateInit success')
2683e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2684e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
2685e41f4b71Sopenharmony_ci  })
2686e41f4b71Sopenharmony_ci  await zip.deflate({ availableOut: 8 }, zlib.CompressFlushMode.FINISH).then((data) => {
2687e41f4b71Sopenharmony_ci    console.info('deflate success')
2688e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2689e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
2690e41f4b71Sopenharmony_ci  })
2691e41f4b71Sopenharmony_ci  await zip.deflateEnd({ nextOut: arrayBufferOut }).then(data => {
2692e41f4b71Sopenharmony_ci    console.info('deflateEnd success')
2693e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2694e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2695e41f4b71Sopenharmony_ci  })
2696e41f4b71Sopenharmony_ci  await zip.inflateInit({ nextIn: arrayBufferOut, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }
2697e41f4b71Sopenharmony_ci  ).then(data => {
2698e41f4b71Sopenharmony_ci    console.info('inflateInit success');
2699e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2700e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2701e41f4b71Sopenharmony_ci  })
2702e41f4b71Sopenharmony_ci  await zip.inflate({ availableIn: 8, availableOut: 8 }, 0).then((data) => {
2703e41f4b71Sopenharmony_ci    console.info('inflate success')
2704e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2705e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2706e41f4b71Sopenharmony_ci  })
2707e41f4b71Sopenharmony_ci  await zip.inflateEnd({ nextOut: arrayBufferOut }).then((data) => {
2708e41f4b71Sopenharmony_ci    console.info('inflateEnd success')
2709e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2710e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2711e41f4b71Sopenharmony_ci  })
2712e41f4b71Sopenharmony_ci}
2713e41f4b71Sopenharmony_ci```
2714e41f4b71Sopenharmony_ci
2715e41f4b71Sopenharmony_ci### deflateInit<sup>12+</sup>
2716e41f4b71Sopenharmony_ci
2717e41f4b71Sopenharmony_cideflateInit(strm: ZStream, level: CompressLevel): Promise&lt;ReturnStatus&gt;
2718e41f4b71Sopenharmony_ci
2719e41f4b71Sopenharmony_ci初始化内部流状态以进行压缩,使用Promise异步返回。成功时返回结果状态。
2720e41f4b71Sopenharmony_ci
2721e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2722e41f4b71Sopenharmony_ci
2723e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2724e41f4b71Sopenharmony_ci
2725e41f4b71Sopenharmony_ci**参数:**
2726e41f4b71Sopenharmony_ci
2727e41f4b71Sopenharmony_ci| 参数名 | 类型          | 必填 | 说明                                                 |
2728e41f4b71Sopenharmony_ci| ------ | ------------- | ---- | ---------------------------------------------------- |
2729e41f4b71Sopenharmony_ci| strm   | ZStream       | 是   | 参考[ZStream定义](#zstream12)。                      |
2730e41f4b71Sopenharmony_ci| level  | CompressLevel | 是   | 参考[zip.CompressLevel枚举定义](#zipcompresslevel)。 |
2731e41f4b71Sopenharmony_ci
2732e41f4b71Sopenharmony_ci**返回值:**
2733e41f4b71Sopenharmony_ci
2734e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
2735e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
2736e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
2737e41f4b71Sopenharmony_ci
2738e41f4b71Sopenharmony_ci**错误码:**
2739e41f4b71Sopenharmony_ci
2740e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
2741e41f4b71Sopenharmony_ci
2742e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2743e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2744e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2745e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
2746e41f4b71Sopenharmony_ci
2747e41f4b71Sopenharmony_ci**示例:**
2748e41f4b71Sopenharmony_ci
2749e41f4b71Sopenharmony_ci```ts
2750e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
2751e41f4b71Sopenharmony_ci
2752e41f4b71Sopenharmony_ciasync function demo() {
2753e41f4b71Sopenharmony_ci  let str = 'hello world!';
2754e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
2755e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
2756e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
2757e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
2758e41f4b71Sopenharmony_ci  }
2759e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
2760e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
2761e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
2762e41f4b71Sopenharmony_ci    availableIn: 1,
2763e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
2764e41f4b71Sopenharmony_ci    availableOut: 1
2765e41f4b71Sopenharmony_ci  };
2766e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
2767e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
2768e41f4b71Sopenharmony_ci    console.info('deflateInit success')
2769e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2770e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
2771e41f4b71Sopenharmony_ci  })
2772e41f4b71Sopenharmony_ci}
2773e41f4b71Sopenharmony_ci```
2774e41f4b71Sopenharmony_ci
2775e41f4b71Sopenharmony_ci### deflateInit2<sup>12+</sup>
2776e41f4b71Sopenharmony_ci
2777e41f4b71Sopenharmony_cideflateInit2(strm: ZStream, level: CompressLevel, method: CompressMethod, windowBits: number, memLevel: MemLevel, strategy: CompressStrategy): Promise&lt;ReturnStatus&gt;
2778e41f4b71Sopenharmony_ci
2779e41f4b71Sopenharmony_ci初始化内部流状态以进行压缩,使用Promise异步返回。成功时返回结果状态。
2780e41f4b71Sopenharmony_ci
2781e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2782e41f4b71Sopenharmony_ci
2783e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2784e41f4b71Sopenharmony_ci
2785e41f4b71Sopenharmony_ci**参数:**
2786e41f4b71Sopenharmony_ci
2787e41f4b71Sopenharmony_ci| 参数名     | 类型             | 必填 | 说明                                                       |
2788e41f4b71Sopenharmony_ci| ---------- | ---------------- | ---- | ---------------------------------------------------------- |
2789e41f4b71Sopenharmony_ci| strm       | ZStream          | 是   | 参考[ZStream定义](#zstream12)。                            |
2790e41f4b71Sopenharmony_ci| level      | CompressLevel    | 是   | 参考[zip.CompressLevel枚举定义](#zipcompresslevel)。       |
2791e41f4b71Sopenharmony_ci| method     | CompressMethod   | 是   | 参考[zip.CompressMethod枚举定义](#zipcompressmethod12)。   |
2792e41f4b71Sopenharmony_ci| windowBits | number           | 是   | 最大窗口大小的以2为底的对数。                              |
2793e41f4b71Sopenharmony_ci| memLevel   | MemLevel         | 是   | 参考[zip.MemLevel枚举定义](#zipmemlevel)。                 |
2794e41f4b71Sopenharmony_ci| strategy   | CompressStrategy | 是   | 参考[zip.CompressStrategy枚举定义](#zipcompressstrategy)。 |
2795e41f4b71Sopenharmony_ci
2796e41f4b71Sopenharmony_ci**返回值:**
2797e41f4b71Sopenharmony_ci
2798e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
2799e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
2800e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
2801e41f4b71Sopenharmony_ci
2802e41f4b71Sopenharmony_ci**错误码:**
2803e41f4b71Sopenharmony_ci
2804e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
2805e41f4b71Sopenharmony_ci
2806e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2807e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2808e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2809e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
2810e41f4b71Sopenharmony_ci
2811e41f4b71Sopenharmony_ci**示例:**
2812e41f4b71Sopenharmony_ci
2813e41f4b71Sopenharmony_ci```ts
2814e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
2815e41f4b71Sopenharmony_ci
2816e41f4b71Sopenharmony_ciasync function demo() {
2817e41f4b71Sopenharmony_ci  let str = 'hello world!';
2818e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
2819e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
2820e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
2821e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
2822e41f4b71Sopenharmony_ci  }
2823e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
2824e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
2825e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
2826e41f4b71Sopenharmony_ci    availableIn: 1,
2827e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
2828e41f4b71Sopenharmony_ci    availableOut: 1
2829e41f4b71Sopenharmony_ci  };
2830e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync()
2831e41f4b71Sopenharmony_ci  await zip.deflateInit2(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED, zlib.CompressMethod.DEFLATED, 28,
2832e41f4b71Sopenharmony_ci    zlib.MemLevel.MEM_LEVEL_DEFAULT, zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY).then((data) => {
2833e41f4b71Sopenharmony_ci      console.info('deflateInit2 success');
2834e41f4b71Sopenharmony_ci    }).catch((errData: BusinessError) => {
2835e41f4b71Sopenharmony_ci      console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
2836e41f4b71Sopenharmony_ci    })
2837e41f4b71Sopenharmony_ci}
2838e41f4b71Sopenharmony_ci```
2839e41f4b71Sopenharmony_ci
2840e41f4b71Sopenharmony_ci### deflate<sup>12+</sup>
2841e41f4b71Sopenharmony_ci
2842e41f4b71Sopenharmony_cideflate(strm: ZStream, flush: CompressFlushMode): Promise&lt;ReturnStatus&gt;
2843e41f4b71Sopenharmony_ci
2844e41f4b71Sopenharmony_ci压缩数据,使用Promise异步返回。成功时返回结果状态。
2845e41f4b71Sopenharmony_ci
2846e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2847e41f4b71Sopenharmony_ci
2848e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2849e41f4b71Sopenharmony_ci
2850e41f4b71Sopenharmony_ci**参数:**
2851e41f4b71Sopenharmony_ci
2852e41f4b71Sopenharmony_ci| 参数名 | 类型              | 必填 | 说明                                                   |
2853e41f4b71Sopenharmony_ci| ------ | ----------------- | ---- | ------------------------------------------------------ |
2854e41f4b71Sopenharmony_ci| strm   | ZStream           | 是   | 参考[ZStream定义](#zstream12)。                        |
2855e41f4b71Sopenharmony_ci| flush  | CompressFlushMode | 是   | 参考[CompressFlushMode定义](#zipcompressflushmode12)。 |
2856e41f4b71Sopenharmony_ci
2857e41f4b71Sopenharmony_ci**返回值:**
2858e41f4b71Sopenharmony_ci
2859e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
2860e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
2861e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
2862e41f4b71Sopenharmony_ci
2863e41f4b71Sopenharmony_ci**错误码:**
2864e41f4b71Sopenharmony_ci
2865e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
2866e41f4b71Sopenharmony_ci
2867e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2868e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2869e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2870e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
2871e41f4b71Sopenharmony_ci| 17800007 | Buffer error.                                                |
2872e41f4b71Sopenharmony_ci
2873e41f4b71Sopenharmony_ci**示例:**
2874e41f4b71Sopenharmony_ci
2875e41f4b71Sopenharmony_ci```ts
2876e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
2877e41f4b71Sopenharmony_ci
2878e41f4b71Sopenharmony_ciasync function demo() {
2879e41f4b71Sopenharmony_ci  let str = 'hello world!';
2880e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
2881e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
2882e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
2883e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
2884e41f4b71Sopenharmony_ci  }
2885e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
2886e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
2887e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
2888e41f4b71Sopenharmony_ci    availableIn: 1,
2889e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
2890e41f4b71Sopenharmony_ci    availableOut: 1
2891e41f4b71Sopenharmony_ci  };
2892e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
2893e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
2894e41f4b71Sopenharmony_ci    console.info('deflateInit success')
2895e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2896e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
2897e41f4b71Sopenharmony_ci  })
2898e41f4b71Sopenharmony_ci  await zip.deflate({ availableOut: 8 }, zlib.CompressFlushMode.FINISH).then((data) => {
2899e41f4b71Sopenharmony_ci    console.info('deflate success')
2900e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2901e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
2902e41f4b71Sopenharmony_ci  })
2903e41f4b71Sopenharmony_ci}
2904e41f4b71Sopenharmony_ci```
2905e41f4b71Sopenharmony_ci
2906e41f4b71Sopenharmony_ci### deflateEnd<sup>12+</sup>
2907e41f4b71Sopenharmony_ci
2908e41f4b71Sopenharmony_cideflateEnd(strm: ZStream): Promise&lt;ReturnStatus&gt;
2909e41f4b71Sopenharmony_ci
2910e41f4b71Sopenharmony_ci压缩流的所有动态分配的数据结构都被释放,使用Promise异步返回。成功时返回结果状态。
2911e41f4b71Sopenharmony_ci
2912e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2913e41f4b71Sopenharmony_ci
2914e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2915e41f4b71Sopenharmony_ci
2916e41f4b71Sopenharmony_ci**参数:**
2917e41f4b71Sopenharmony_ci
2918e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
2919e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
2920e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
2921e41f4b71Sopenharmony_ci
2922e41f4b71Sopenharmony_ci**返回值:**
2923e41f4b71Sopenharmony_ci
2924e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
2925e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
2926e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
2927e41f4b71Sopenharmony_ci
2928e41f4b71Sopenharmony_ci**错误码:**
2929e41f4b71Sopenharmony_ci
2930e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
2931e41f4b71Sopenharmony_ci
2932e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2933e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2934e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
2935e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
2936e41f4b71Sopenharmony_ci
2937e41f4b71Sopenharmony_ci**示例:**
2938e41f4b71Sopenharmony_ci
2939e41f4b71Sopenharmony_ci```ts
2940e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
2941e41f4b71Sopenharmony_ci
2942e41f4b71Sopenharmony_ciasync function demo() {
2943e41f4b71Sopenharmony_ci  let str = 'hello world!';
2944e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
2945e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
2946e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
2947e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
2948e41f4b71Sopenharmony_ci  }
2949e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
2950e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
2951e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
2952e41f4b71Sopenharmony_ci    availableIn: 1,
2953e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
2954e41f4b71Sopenharmony_ci    availableOut: 1
2955e41f4b71Sopenharmony_ci  };
2956e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
2957e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
2958e41f4b71Sopenharmony_ci    console.info('deflateInit success')
2959e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2960e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
2961e41f4b71Sopenharmony_ci  })
2962e41f4b71Sopenharmony_ci  await zip.deflate({ availableOut: 8 }, zlib.CompressFlushMode.FINISH).then((data) => {
2963e41f4b71Sopenharmony_ci    console.info('deflate success')
2964e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2965e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
2966e41f4b71Sopenharmony_ci  })
2967e41f4b71Sopenharmony_ci  await zip.deflateEnd({ nextOut: arrayBufferOut }).then(data => {
2968e41f4b71Sopenharmony_ci    console.info('deflateEnd success')
2969e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
2970e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
2971e41f4b71Sopenharmony_ci  })
2972e41f4b71Sopenharmony_ci}
2973e41f4b71Sopenharmony_ci```
2974e41f4b71Sopenharmony_ci
2975e41f4b71Sopenharmony_ci### deflateBound<sup>12+</sup>
2976e41f4b71Sopenharmony_ci
2977e41f4b71Sopenharmony_cideflateBound(strm: ZStream, sourceLength: number): Promise&lt;number&gt;
2978e41f4b71Sopenharmony_ci
2979e41f4b71Sopenharmony_ci计算压缩大小的上限,使用Promise异步返回。成功时返回压缩大小的上限。
2980e41f4b71Sopenharmony_ci
2981e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2982e41f4b71Sopenharmony_ci
2983e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
2984e41f4b71Sopenharmony_ci
2985e41f4b71Sopenharmony_ci**参数:**
2986e41f4b71Sopenharmony_ci
2987e41f4b71Sopenharmony_ci| 参数名    | 类型    | 必填 | 说明                            |
2988e41f4b71Sopenharmony_ci| --------- | ------- | ---- | ------------------------------- |
2989e41f4b71Sopenharmony_ci| strm      | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
2990e41f4b71Sopenharmony_ci| sourceLength | number  | 是   | 源数据长度。                    |
2991e41f4b71Sopenharmony_ci
2992e41f4b71Sopenharmony_ci**返回值:**
2993e41f4b71Sopenharmony_ci
2994e41f4b71Sopenharmony_ci| 类型                  | 说明                              |
2995e41f4b71Sopenharmony_ci| --------------------- | --------------------------------- |
2996e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象。返回压缩大小的上限。 |
2997e41f4b71Sopenharmony_ci
2998e41f4b71Sopenharmony_ci**错误码:**
2999e41f4b71Sopenharmony_ci
3000e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3001e41f4b71Sopenharmony_ci
3002e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3003e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3004e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
3005e41f4b71Sopenharmony_ci
3006e41f4b71Sopenharmony_ci**示例:**
3007e41f4b71Sopenharmony_ci
3008e41f4b71Sopenharmony_ci```ts
3009e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
3010e41f4b71Sopenharmony_ci
3011e41f4b71Sopenharmony_ciasync function demo() {
3012e41f4b71Sopenharmony_ci  let str = 'hello world!';
3013e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
3014e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
3015e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
3016e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
3017e41f4b71Sopenharmony_ci  }
3018e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
3019e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
3020e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
3021e41f4b71Sopenharmony_ci    availableIn: 1,
3022e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
3023e41f4b71Sopenharmony_ci    availableOut: 1
3024e41f4b71Sopenharmony_ci  };
3025e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
3026e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
3027e41f4b71Sopenharmony_ci    console.info('deflateInit success')
3028e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3029e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3030e41f4b71Sopenharmony_ci  })
3031e41f4b71Sopenharmony_ci  await zip.deflateBound({ nextOut: arrayBufferOut }, 12).then((data) => {
3032e41f4b71Sopenharmony_ci    console.info('deflateBound success')
3033e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3034e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3035e41f4b71Sopenharmony_ci  })
3036e41f4b71Sopenharmony_ci}
3037e41f4b71Sopenharmony_ci```
3038e41f4b71Sopenharmony_ci
3039e41f4b71Sopenharmony_ci### deflateSetHeader<sup>12+</sup>
3040e41f4b71Sopenharmony_ci
3041e41f4b71Sopenharmony_cideflateSetHeader(strm: ZStream, head: GzHeader): Promise&lt;ReturnStatus&gt;
3042e41f4b71Sopenharmony_ci
3043e41f4b71Sopenharmony_ci当deflateInit2()请求gzip流时,提供gzip标头信息,使用Promise异步返回。成功时返回结果状态。
3044e41f4b71Sopenharmony_ci
3045e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3046e41f4b71Sopenharmony_ci
3047e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3048e41f4b71Sopenharmony_ci
3049e41f4b71Sopenharmony_ci**参数:**
3050e41f4b71Sopenharmony_ci
3051e41f4b71Sopenharmony_ci| 参数名 | 类型                    | 必填 | 说明                             |
3052e41f4b71Sopenharmony_ci| ------ | ----------------------- | ---- | -------------------------------- |
3053e41f4b71Sopenharmony_ci| strm   | ZStream                 | 是   | 参考[ZStream定义](#zstream12)。  |
3054e41f4b71Sopenharmony_ci| head   | [GzHeader](#gzheader12) | 是   | 从压缩数据流中提取的gzip头信息。 |
3055e41f4b71Sopenharmony_ci
3056e41f4b71Sopenharmony_ci**返回值:**
3057e41f4b71Sopenharmony_ci
3058e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
3059e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
3060e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
3061e41f4b71Sopenharmony_ci
3062e41f4b71Sopenharmony_ci**错误码:**
3063e41f4b71Sopenharmony_ci
3064e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
3065e41f4b71Sopenharmony_ci
3066e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3067e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3068e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
3069e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
3070e41f4b71Sopenharmony_ci
3071e41f4b71Sopenharmony_ci**示例:**
3072e41f4b71Sopenharmony_ci
3073e41f4b71Sopenharmony_ci```ts
3074e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
3075e41f4b71Sopenharmony_ci
3076e41f4b71Sopenharmony_ciasync function demo() {
3077e41f4b71Sopenharmony_ci  let str = 'hello world!';
3078e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
3079e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
3080e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
3081e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
3082e41f4b71Sopenharmony_ci  }
3083e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
3084e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
3085e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
3086e41f4b71Sopenharmony_ci    availableIn: 1,
3087e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
3088e41f4b71Sopenharmony_ci    availableOut: 1
3089e41f4b71Sopenharmony_ci  };
3090e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync()
3091e41f4b71Sopenharmony_ci  await zip.deflateInit2(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED, zlib.CompressMethod.DEFLATED, 28,
3092e41f4b71Sopenharmony_ci    zlib.MemLevel.MEM_LEVEL_DEFAULT, zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY).then((data) => {
3093e41f4b71Sopenharmony_ci      console.info('deflateInit2 success');
3094e41f4b71Sopenharmony_ci    }).catch((errData: BusinessError) => {
3095e41f4b71Sopenharmony_ci      console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
3096e41f4b71Sopenharmony_ci    })
3097e41f4b71Sopenharmony_ci  await zip.deflateSetHeader({ nextIn: arrayBufferIn, availableIn: 1, nextOut: arrayBufferOut, availableOut: 1 }, { isText: true, os: 1, time: 1, xflags: 1, extra: arrayBufferIn, extraLen: 12, name: arrayBufferIn, comment: arrayBufferOut, hcrc: true, done: true }).then((data) => {
3098e41f4b71Sopenharmony_ci    console.info('deflateSetHeader success');
3099e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3100e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`)
3101e41f4b71Sopenharmony_ci  })
3102e41f4b71Sopenharmony_ci}
3103e41f4b71Sopenharmony_ci```
3104e41f4b71Sopenharmony_ci
3105e41f4b71Sopenharmony_ci### deflateCopy<sup>12+</sup>
3106e41f4b71Sopenharmony_ci
3107e41f4b71Sopenharmony_cideflateCopy(source: Zip): Promise&lt;ReturnStatus&gt;
3108e41f4b71Sopenharmony_ci
3109e41f4b71Sopenharmony_ci复制压缩流,使用Promise异步返回。成功时返回结果状态。
3110e41f4b71Sopenharmony_ci
3111e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3112e41f4b71Sopenharmony_ci
3113e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3114e41f4b71Sopenharmony_ci
3115e41f4b71Sopenharmony_ci**参数:**
3116e41f4b71Sopenharmony_ci
3117e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明                    |
3118e41f4b71Sopenharmony_ci| ------ | ---- | ---- | ----------------------- |
3119e41f4b71Sopenharmony_ci| source | Zip  | 是   | 参考[Zip定义](#zip12)。 |
3120e41f4b71Sopenharmony_ci
3121e41f4b71Sopenharmony_ci**返回值:**
3122e41f4b71Sopenharmony_ci
3123e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
3124e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
3125e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
3126e41f4b71Sopenharmony_ci
3127e41f4b71Sopenharmony_ci**错误码:**
3128e41f4b71Sopenharmony_ci
3129e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
3130e41f4b71Sopenharmony_ci
3131e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3132e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3133e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
3134e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
3135e41f4b71Sopenharmony_ci
3136e41f4b71Sopenharmony_ci**示例:**
3137e41f4b71Sopenharmony_ci
3138e41f4b71Sopenharmony_ci```ts
3139e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
3140e41f4b71Sopenharmony_ci
3141e41f4b71Sopenharmony_ciasync function demo() {
3142e41f4b71Sopenharmony_ci  let str = 'hello world!';
3143e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
3144e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
3145e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
3146e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
3147e41f4b71Sopenharmony_ci  }
3148e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
3149e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
3150e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
3151e41f4b71Sopenharmony_ci    availableIn: 1,
3152e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
3153e41f4b71Sopenharmony_ci    availableOut: 1
3154e41f4b71Sopenharmony_ci  };
3155e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
3156e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
3157e41f4b71Sopenharmony_ci    console.info('deflateInit success')
3158e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3159e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3160e41f4b71Sopenharmony_ci  })
3161e41f4b71Sopenharmony_ci  await zip.deflateCopy(zip).then((data) => {
3162e41f4b71Sopenharmony_ci    console.info('deflateCopy success')
3163e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3164e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3165e41f4b71Sopenharmony_ci  })
3166e41f4b71Sopenharmony_ci}
3167e41f4b71Sopenharmony_ci```
3168e41f4b71Sopenharmony_ci
3169e41f4b71Sopenharmony_ci### deflateSetDictionary<sup>12+</sup>
3170e41f4b71Sopenharmony_ci
3171e41f4b71Sopenharmony_cideflateSetDictionary(strm: ZStream, dictionary: ArrayBuffer): Promise&lt;ReturnStatus&gt;
3172e41f4b71Sopenharmony_ci
3173e41f4b71Sopenharmony_ci从给定的字节序列初始化压缩字典,使用Promise异步返回。成功时返回结果状态。
3174e41f4b71Sopenharmony_ci
3175e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3176e41f4b71Sopenharmony_ci
3177e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3178e41f4b71Sopenharmony_ci
3179e41f4b71Sopenharmony_ci**参数:**
3180e41f4b71Sopenharmony_ci
3181e41f4b71Sopenharmony_ci| 参数名     | 类型        | 必填 | 说明                            |
3182e41f4b71Sopenharmony_ci| ---------- | ----------- | ---- | ------------------------------- |
3183e41f4b71Sopenharmony_ci| strm       | ZStream     | 是   | 参考[ZStream定义](#zstream12)。 |
3184e41f4b71Sopenharmony_ci| dictionary | ArrayBuffer | 是   | 字典数据。                      |
3185e41f4b71Sopenharmony_ci
3186e41f4b71Sopenharmony_ci**返回值:**
3187e41f4b71Sopenharmony_ci
3188e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
3189e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
3190e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
3191e41f4b71Sopenharmony_ci
3192e41f4b71Sopenharmony_ci**错误码:**
3193e41f4b71Sopenharmony_ci
3194e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
3195e41f4b71Sopenharmony_ci
3196e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3197e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3198e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
3199e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
3200e41f4b71Sopenharmony_ci
3201e41f4b71Sopenharmony_ci**示例:**
3202e41f4b71Sopenharmony_ci
3203e41f4b71Sopenharmony_ci```ts
3204e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
3205e41f4b71Sopenharmony_ci
3206e41f4b71Sopenharmony_ciasync function demo() {
3207e41f4b71Sopenharmony_ci  let str = 'hello world!';
3208e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
3209e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
3210e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
3211e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
3212e41f4b71Sopenharmony_ci  }
3213e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
3214e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
3215e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
3216e41f4b71Sopenharmony_ci    availableIn: 1,
3217e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
3218e41f4b71Sopenharmony_ci    availableOut: 1
3219e41f4b71Sopenharmony_ci  };
3220e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
3221e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
3222e41f4b71Sopenharmony_ci    console.info('deflateInit success')
3223e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3224e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3225e41f4b71Sopenharmony_ci  })
3226e41f4b71Sopenharmony_ci  await zip.deflateSetDictionary({ nextOut: arrayBufferOut }, arrayBufferOut).then((data) => {
3227e41f4b71Sopenharmony_ci    console.info('deflateSetDictionary success')
3228e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3229e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3230e41f4b71Sopenharmony_ci  })
3231e41f4b71Sopenharmony_ci}
3232e41f4b71Sopenharmony_ci```
3233e41f4b71Sopenharmony_ci
3234e41f4b71Sopenharmony_ci### deflateGetDictionary<sup>12+</sup>
3235e41f4b71Sopenharmony_ci
3236e41f4b71Sopenharmony_cideflateGetDictionary(strm: ZStream, dictionary: ArrayBuffer): Promise&lt;DictionaryOutputInfo&gt;
3237e41f4b71Sopenharmony_ci
3238e41f4b71Sopenharmony_ci获取当前解压缩流中使用的解压缩字典内容及其长度,使用Promise异步返回。成功时返回结果状态和字典的长度。
3239e41f4b71Sopenharmony_ci
3240e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3241e41f4b71Sopenharmony_ci
3242e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3243e41f4b71Sopenharmony_ci
3244e41f4b71Sopenharmony_ci**参数:**
3245e41f4b71Sopenharmony_ci
3246e41f4b71Sopenharmony_ci| 参数名     | 类型        | 必填 | 说明                            |
3247e41f4b71Sopenharmony_ci| ---------- | ----------- | ---- | ------------------------------- |
3248e41f4b71Sopenharmony_ci| strm       | ZStream     | 是   | 参考[ZStream定义](#zstream12)。 |
3249e41f4b71Sopenharmony_ci| dictionary | ArrayBuffer | 是   | 接收解压缩字典的实际内容。      |
3250e41f4b71Sopenharmony_ci
3251e41f4b71Sopenharmony_ci**返回值:**
3252e41f4b71Sopenharmony_ci
3253e41f4b71Sopenharmony_ci| 类型                                                         | 说明                                    |
3254e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | --------------------------------------- |
3255e41f4b71Sopenharmony_ci| Promise&lt;[DictionaryOutputInfo](#dictionaryoutputinfo12)&gt; | Promise对象。返回结果状态和字典的长度。 |
3256e41f4b71Sopenharmony_ci
3257e41f4b71Sopenharmony_ci**错误码:**
3258e41f4b71Sopenharmony_ci
3259e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
3260e41f4b71Sopenharmony_ci
3261e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3262e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3263e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
3264e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
3265e41f4b71Sopenharmony_ci
3266e41f4b71Sopenharmony_ci**示例:**
3267e41f4b71Sopenharmony_ci
3268e41f4b71Sopenharmony_ci```ts
3269e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
3270e41f4b71Sopenharmony_ci
3271e41f4b71Sopenharmony_ciasync function demo() {
3272e41f4b71Sopenharmony_ci  let str = 'hello world!';
3273e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
3274e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
3275e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
3276e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
3277e41f4b71Sopenharmony_ci  }
3278e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
3279e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
3280e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
3281e41f4b71Sopenharmony_ci    availableIn: 1,
3282e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
3283e41f4b71Sopenharmony_ci    availableOut: 1
3284e41f4b71Sopenharmony_ci  };
3285e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
3286e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
3287e41f4b71Sopenharmony_ci    console.info('deflateInit success')
3288e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3289e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3290e41f4b71Sopenharmony_ci  })
3291e41f4b71Sopenharmony_ci  await zip.deflateSetDictionary({ nextOut: arrayBufferOut }, arrayBufferOut).then((data) => {
3292e41f4b71Sopenharmony_ci    console.info('deflateSetDictionary success')
3293e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3294e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3295e41f4b71Sopenharmony_ci  })
3296e41f4b71Sopenharmony_ci  await zip.deflateGetDictionary({ nextOut: arrayBufferOut }, arrayBufferOut).then((data) => {
3297e41f4b71Sopenharmony_ci    console.info('deflateGetDictionary success')
3298e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3299e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3300e41f4b71Sopenharmony_ci  })
3301e41f4b71Sopenharmony_ci}
3302e41f4b71Sopenharmony_ci```
3303e41f4b71Sopenharmony_ci
3304e41f4b71Sopenharmony_ci### deflateTune<sup>12+</sup>
3305e41f4b71Sopenharmony_ci
3306e41f4b71Sopenharmony_cideflateTune(strm: ZStream, goodLength: number, maxLazy: number, niceLength: number, maxChain: number): Promise&lt;ReturnStatus&gt;
3307e41f4b71Sopenharmony_ci
3308e41f4b71Sopenharmony_ci微调deflate的内部压缩参数,使用Promise异步返回。成功时返回结果状态。
3309e41f4b71Sopenharmony_ci
3310e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3311e41f4b71Sopenharmony_ci
3312e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3313e41f4b71Sopenharmony_ci
3314e41f4b71Sopenharmony_ci**参数:**
3315e41f4b71Sopenharmony_ci
3316e41f4b71Sopenharmony_ci| 参数名     | 类型    | 必填 | 说明                            |
3317e41f4b71Sopenharmony_ci| ---------- | ------- | ---- | ------------------------------- |
3318e41f4b71Sopenharmony_ci| strm       | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
3319e41f4b71Sopenharmony_ci| goodLength | number  | 是   | 匹配的长度阈值。                |
3320e41f4b71Sopenharmony_ci| maxLazy    | number  | 是   | 最大延迟匹配时间。              |
3321e41f4b71Sopenharmony_ci| niceLength | number  | 是   | 适合的延迟长度阈值              |
3322e41f4b71Sopenharmony_ci| maxChain   | number  | 是   | 最大链条长度                    |
3323e41f4b71Sopenharmony_ci
3324e41f4b71Sopenharmony_ci**返回值:**
3325e41f4b71Sopenharmony_ci
3326e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
3327e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
3328e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
3329e41f4b71Sopenharmony_ci
3330e41f4b71Sopenharmony_ci**错误码:**
3331e41f4b71Sopenharmony_ci
3332e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
3333e41f4b71Sopenharmony_ci
3334e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3335e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3336e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
3337e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
3338e41f4b71Sopenharmony_ci
3339e41f4b71Sopenharmony_ci**示例:**
3340e41f4b71Sopenharmony_ci
3341e41f4b71Sopenharmony_ci```ts
3342e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
3343e41f4b71Sopenharmony_ci
3344e41f4b71Sopenharmony_ciasync function demo() {
3345e41f4b71Sopenharmony_ci  let str = 'hello world!';
3346e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
3347e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
3348e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
3349e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
3350e41f4b71Sopenharmony_ci  }
3351e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
3352e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
3353e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
3354e41f4b71Sopenharmony_ci    availableIn: 1,
3355e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
3356e41f4b71Sopenharmony_ci    availableOut: 1
3357e41f4b71Sopenharmony_ci  };
3358e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
3359e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
3360e41f4b71Sopenharmony_ci    console.info('deflateInit success')
3361e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3362e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3363e41f4b71Sopenharmony_ci  })
3364e41f4b71Sopenharmony_ci  await zip.deflateTune({ nextOut: arrayBufferOut }, 2, 2, 2, 2).then((data) => {
3365e41f4b71Sopenharmony_ci    console.info('deflateTune success:')
3366e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3367e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3368e41f4b71Sopenharmony_ci  })
3369e41f4b71Sopenharmony_ci}
3370e41f4b71Sopenharmony_ci```
3371e41f4b71Sopenharmony_ci
3372e41f4b71Sopenharmony_ci### deflateReset<sup>12+</sup>
3373e41f4b71Sopenharmony_ci
3374e41f4b71Sopenharmony_cideflateReset(strm: ZStream): Promise&lt;ReturnStatus&gt;
3375e41f4b71Sopenharmony_ci
3376e41f4b71Sopenharmony_ci这个函数相当于先调用deflateEnd再调用deflateInit,但是并不会释放和重新分配内部解压缩状态,使用Promise异步返回。成功时返回结果状态。
3377e41f4b71Sopenharmony_ci
3378e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3379e41f4b71Sopenharmony_ci
3380e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3381e41f4b71Sopenharmony_ci
3382e41f4b71Sopenharmony_ci**参数:**
3383e41f4b71Sopenharmony_ci
3384e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
3385e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
3386e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
3387e41f4b71Sopenharmony_ci
3388e41f4b71Sopenharmony_ci**返回值:**
3389e41f4b71Sopenharmony_ci
3390e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
3391e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
3392e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
3393e41f4b71Sopenharmony_ci
3394e41f4b71Sopenharmony_ci**错误码:**
3395e41f4b71Sopenharmony_ci
3396e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
3397e41f4b71Sopenharmony_ci
3398e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3399e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3400e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
3401e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
3402e41f4b71Sopenharmony_ci
3403e41f4b71Sopenharmony_ci**示例:**
3404e41f4b71Sopenharmony_ci
3405e41f4b71Sopenharmony_ci```ts
3406e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
3407e41f4b71Sopenharmony_ci
3408e41f4b71Sopenharmony_ciasync function demo() {
3409e41f4b71Sopenharmony_ci  let str = 'hello world!';
3410e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
3411e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
3412e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
3413e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
3414e41f4b71Sopenharmony_ci  }
3415e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
3416e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
3417e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
3418e41f4b71Sopenharmony_ci    availableIn: 1,
3419e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
3420e41f4b71Sopenharmony_ci    availableOut: 1
3421e41f4b71Sopenharmony_ci  };
3422e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
3423e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
3424e41f4b71Sopenharmony_ci    console.info('deflateInit success')
3425e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3426e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3427e41f4b71Sopenharmony_ci  })
3428e41f4b71Sopenharmony_ci  await zip.deflateReset({ nextOut: arrayBufferOut }).then((data) => {
3429e41f4b71Sopenharmony_ci    console.info('deflateReset success')
3430e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3431e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3432e41f4b71Sopenharmony_ci  })
3433e41f4b71Sopenharmony_ci}
3434e41f4b71Sopenharmony_ci```
3435e41f4b71Sopenharmony_ci
3436e41f4b71Sopenharmony_ci### deflateResetKeep<sup>12+</sup>
3437e41f4b71Sopenharmony_ci
3438e41f4b71Sopenharmony_cideflateResetKeep(strm: ZStream): Promise&lt;ReturnStatus&gt;
3439e41f4b71Sopenharmony_ci
3440e41f4b71Sopenharmony_ci重置初始化的deflate压缩流,但保留其设置的压缩参数和字典,使用Promise异步返回。成功时返回结果状态。
3441e41f4b71Sopenharmony_ci
3442e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3443e41f4b71Sopenharmony_ci
3444e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3445e41f4b71Sopenharmony_ci
3446e41f4b71Sopenharmony_ci**参数:**
3447e41f4b71Sopenharmony_ci
3448e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
3449e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
3450e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
3451e41f4b71Sopenharmony_ci
3452e41f4b71Sopenharmony_ci**返回值:**
3453e41f4b71Sopenharmony_ci
3454e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
3455e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
3456e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
3457e41f4b71Sopenharmony_ci
3458e41f4b71Sopenharmony_ci**错误码:**
3459e41f4b71Sopenharmony_ci
3460e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
3461e41f4b71Sopenharmony_ci
3462e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3463e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3464e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
3465e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
3466e41f4b71Sopenharmony_ci
3467e41f4b71Sopenharmony_ci**示例:**
3468e41f4b71Sopenharmony_ci
3469e41f4b71Sopenharmony_ci```ts
3470e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
3471e41f4b71Sopenharmony_ci
3472e41f4b71Sopenharmony_ciasync function demo() {
3473e41f4b71Sopenharmony_ci  let str = 'hello world!';
3474e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
3475e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
3476e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
3477e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
3478e41f4b71Sopenharmony_ci  }
3479e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
3480e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
3481e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
3482e41f4b71Sopenharmony_ci    availableIn: 1,
3483e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
3484e41f4b71Sopenharmony_ci    availableOut: 1
3485e41f4b71Sopenharmony_ci  };
3486e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
3487e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
3488e41f4b71Sopenharmony_ci    console.info('deflateInit success')
3489e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3490e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3491e41f4b71Sopenharmony_ci  })
3492e41f4b71Sopenharmony_ci  await zip.deflateResetKeep({ nextOut: arrayBufferOut }).then((data) => {
3493e41f4b71Sopenharmony_ci    console.info('deflateResetKeep success')
3494e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3495e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3496e41f4b71Sopenharmony_ci  })
3497e41f4b71Sopenharmony_ci}
3498e41f4b71Sopenharmony_ci```
3499e41f4b71Sopenharmony_ci
3500e41f4b71Sopenharmony_ci### deflatePending<sup>12+</sup>
3501e41f4b71Sopenharmony_ci
3502e41f4b71Sopenharmony_cideflatePending(strm: ZStream): Promise&lt;DeflatePendingOutputInfo&gt;
3503e41f4b71Sopenharmony_ci
3504e41f4b71Sopenharmony_ci返回已生成但尚未在可用输出中提供的输出的字节数和位数,使用Promise异步返回。成功时返回结果状态、输出位数和输出字节数。
3505e41f4b71Sopenharmony_ci
3506e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3507e41f4b71Sopenharmony_ci
3508e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3509e41f4b71Sopenharmony_ci
3510e41f4b71Sopenharmony_ci**参数:**
3511e41f4b71Sopenharmony_ci
3512e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
3513e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
3514e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
3515e41f4b71Sopenharmony_ci
3516e41f4b71Sopenharmony_ci**返回值:**
3517e41f4b71Sopenharmony_ci
3518e41f4b71Sopenharmony_ci| 类型                                                         | 说明                                              |
3519e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------- |
3520e41f4b71Sopenharmony_ci| Promise&lt;[DeflatePendingOutputInfo](#deflatependingoutputinfo12)&gt; | Promise对象。返回结果状态、输出位数和输出字节数。 |
3521e41f4b71Sopenharmony_ci
3522e41f4b71Sopenharmony_ci**错误码:**
3523e41f4b71Sopenharmony_ci
3524e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
3525e41f4b71Sopenharmony_ci
3526e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3527e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3528e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
3529e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
3530e41f4b71Sopenharmony_ci
3531e41f4b71Sopenharmony_ci**示例:**
3532e41f4b71Sopenharmony_ci
3533e41f4b71Sopenharmony_ci```ts
3534e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
3535e41f4b71Sopenharmony_ci
3536e41f4b71Sopenharmony_ciasync function demo() {
3537e41f4b71Sopenharmony_ci  let str = 'hello world!';
3538e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
3539e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
3540e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
3541e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
3542e41f4b71Sopenharmony_ci  }
3543e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
3544e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
3545e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
3546e41f4b71Sopenharmony_ci    availableIn: 1,
3547e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
3548e41f4b71Sopenharmony_ci    availableOut: 1
3549e41f4b71Sopenharmony_ci  };
3550e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
3551e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
3552e41f4b71Sopenharmony_ci    console.info('deflateInit success')
3553e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3554e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3555e41f4b71Sopenharmony_ci  })
3556e41f4b71Sopenharmony_ci  await zip.deflatePending({ nextOut: arrayBufferOut }).then((data) => {
3557e41f4b71Sopenharmony_ci    console.info('deflatePending success')
3558e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3559e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3560e41f4b71Sopenharmony_ci  })
3561e41f4b71Sopenharmony_ci}
3562e41f4b71Sopenharmony_ci```
3563e41f4b71Sopenharmony_ci
3564e41f4b71Sopenharmony_ci### deflateParams<sup>12+</sup>
3565e41f4b71Sopenharmony_ci
3566e41f4b71Sopenharmony_cideflateParams(strm: ZStream, level: CompressLevel, strategy: CompressStrategy): Promise&lt;ReturnStatus&gt;
3567e41f4b71Sopenharmony_ci
3568e41f4b71Sopenharmony_ci动态更新压缩级别和压缩策略,使用Promise异步返回。成功时返回结果状态。
3569e41f4b71Sopenharmony_ci
3570e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3571e41f4b71Sopenharmony_ci
3572e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3573e41f4b71Sopenharmony_ci
3574e41f4b71Sopenharmony_ci**参数:**
3575e41f4b71Sopenharmony_ci
3576e41f4b71Sopenharmony_ci| 参数名   | 类型             | 必填 | 说明                                                       |
3577e41f4b71Sopenharmony_ci| -------- | ---------------- | ---- | ---------------------------------------------------------- |
3578e41f4b71Sopenharmony_ci| strm     | ZStream          | 是   | 参考[ZStream定义](#zstream12)。                            |
3579e41f4b71Sopenharmony_ci| level    | CompressLevel    | 是   | 参考[zip.CompressLevel枚举定义](#zipcompresslevel)。       |
3580e41f4b71Sopenharmony_ci| strategy | CompressStrategy | 是   | 参考[zip.CompressStrategy枚举定义](#zipcompressstrategy)。 |
3581e41f4b71Sopenharmony_ci
3582e41f4b71Sopenharmony_ci**返回值:**
3583e41f4b71Sopenharmony_ci
3584e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
3585e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
3586e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
3587e41f4b71Sopenharmony_ci
3588e41f4b71Sopenharmony_ci**错误码:**
3589e41f4b71Sopenharmony_ci
3590e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
3591e41f4b71Sopenharmony_ci
3592e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3593e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3594e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
3595e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
3596e41f4b71Sopenharmony_ci
3597e41f4b71Sopenharmony_ci**示例:**
3598e41f4b71Sopenharmony_ci
3599e41f4b71Sopenharmony_ci```ts
3600e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
3601e41f4b71Sopenharmony_ci
3602e41f4b71Sopenharmony_ciasync function demo() {
3603e41f4b71Sopenharmony_ci  let str = 'hello world!';
3604e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
3605e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
3606e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
3607e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
3608e41f4b71Sopenharmony_ci  }
3609e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
3610e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
3611e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
3612e41f4b71Sopenharmony_ci    availableIn: 1,
3613e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
3614e41f4b71Sopenharmony_ci    availableOut: 1
3615e41f4b71Sopenharmony_ci  };
3616e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync()
3617e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
3618e41f4b71Sopenharmony_ci    console.info('deflateInit success')
3619e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3620e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3621e41f4b71Sopenharmony_ci  })
3622e41f4b71Sopenharmony_ci  await zip.deflateParams(zStream, zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION, zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY).then((data) => {
3623e41f4b71Sopenharmony_ci    console.info('deflateParams success')
3624e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3625e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3626e41f4b71Sopenharmony_ci  })
3627e41f4b71Sopenharmony_ci}
3628e41f4b71Sopenharmony_ci```
3629e41f4b71Sopenharmony_ci
3630e41f4b71Sopenharmony_ci### deflatePrime<sup>12+</sup>
3631e41f4b71Sopenharmony_ci
3632e41f4b71Sopenharmony_cideflatePrime(strm: ZStream, bits: number, value: number): Promise&lt;ReturnStatus&gt;
3633e41f4b71Sopenharmony_ci
3634e41f4b71Sopenharmony_ci在压缩流中插入位和值,使用Promise异步返回。成功时返回结果状态。
3635e41f4b71Sopenharmony_ci
3636e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3637e41f4b71Sopenharmony_ci
3638e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3639e41f4b71Sopenharmony_ci
3640e41f4b71Sopenharmony_ci**参数:**
3641e41f4b71Sopenharmony_ci
3642e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                            |
3643e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
3644e41f4b71Sopenharmony_ci| strm   | ZStream | 是   | 参考[ZStream定义](#zstream12)。 |
3645e41f4b71Sopenharmony_ci| bits   | number  | 是   | 要插入的位数,取值范围在0~16。  |
3646e41f4b71Sopenharmony_ci| value  | number  | 是   | 与位数相对应的位值。            |
3647e41f4b71Sopenharmony_ci
3648e41f4b71Sopenharmony_ci**返回值:**
3649e41f4b71Sopenharmony_ci
3650e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
3651e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
3652e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象。返回结果状态。 |
3653e41f4b71Sopenharmony_ci
3654e41f4b71Sopenharmony_ci**错误码:**
3655e41f4b71Sopenharmony_ci
3656e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
3657e41f4b71Sopenharmony_ci
3658e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3659e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3660e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
3661e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
3662e41f4b71Sopenharmony_ci
3663e41f4b71Sopenharmony_ci**示例:**
3664e41f4b71Sopenharmony_ci
3665e41f4b71Sopenharmony_ci```ts
3666e41f4b71Sopenharmony_ciimport { zlib, BusinessError } from '@kit.BasicServicesKit';
3667e41f4b71Sopenharmony_ci
3668e41f4b71Sopenharmony_ciasync function demo() {
3669e41f4b71Sopenharmony_ci  let str = 'hello world!';
3670e41f4b71Sopenharmony_ci  let arrayBufferIn = new ArrayBuffer(str.length);
3671e41f4b71Sopenharmony_ci  let byteArray = new Uint8Array(arrayBufferIn);
3672e41f4b71Sopenharmony_ci  for (let i = 0, j = str.length; i < j; i++) {
3673e41f4b71Sopenharmony_ci    byteArray[i] = str.charCodeAt(i)
3674e41f4b71Sopenharmony_ci  }
3675e41f4b71Sopenharmony_ci  let arrayBufferOut = new ArrayBuffer(100);
3676e41f4b71Sopenharmony_ci  let zStream: zlib.ZStream = {
3677e41f4b71Sopenharmony_ci    nextIn: arrayBufferIn,
3678e41f4b71Sopenharmony_ci    availableIn: 1,
3679e41f4b71Sopenharmony_ci    nextOut: arrayBufferOut,
3680e41f4b71Sopenharmony_ci    availableOut: 1
3681e41f4b71Sopenharmony_ci  };
3682e41f4b71Sopenharmony_ci  let zip = zlib.createZipSync();
3683e41f4b71Sopenharmony_ci  await zip.deflateInit(zStream, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED).then((data) => {
3684e41f4b71Sopenharmony_ci    console.info('deflateInit success')
3685e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3686e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3687e41f4b71Sopenharmony_ci  })
3688e41f4b71Sopenharmony_ci  await zip.deflatePrime({ nextOut: arrayBufferOut }, 5, 2).then((data) => {
3689e41f4b71Sopenharmony_ci    console.info('deflatePrime success')
3690e41f4b71Sopenharmony_ci  }).catch((errData: BusinessError) => {
3691e41f4b71Sopenharmony_ci    console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
3692e41f4b71Sopenharmony_ci  })
3693e41f4b71Sopenharmony_ci}
3694e41f4b71Sopenharmony_ci```
3695e41f4b71Sopenharmony_ci
3696e41f4b71Sopenharmony_ci## Options
3697e41f4b71Sopenharmony_ci
3698e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3699e41f4b71Sopenharmony_ci
3700e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3701e41f4b71Sopenharmony_ci
3702e41f4b71Sopenharmony_ci| 名称     | 类型             | 可读 | 可写 | 说明                                                       |
3703e41f4b71Sopenharmony_ci| -------- | ---------------- | ---- | ---- | ---------------------------------------------------------- |
3704e41f4b71Sopenharmony_ci| level    | CompressLevel     | 是   | 否   | 参考[zip.CompressLevel枚举定义](#zipcompresslevel)。       |
3705e41f4b71Sopenharmony_ci| memLevel | MemLevel         | 是   | 否   | 参考[zip.MemLevel枚举定义](#zipmemlevel)。                 |
3706e41f4b71Sopenharmony_ci| strategy | CompressStrategy | 是   | 否   | 参考[zip.CompressStrategy枚举定义](#zipcompressstrategy)。 |
3707e41f4b71Sopenharmony_ci
3708e41f4b71Sopenharmony_ci## zip.CompressLevel
3709e41f4b71Sopenharmony_ci
3710e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3711e41f4b71Sopenharmony_ci
3712e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3713e41f4b71Sopenharmony_ci
3714e41f4b71Sopenharmony_ci| 名称                               | 值   | 说明              |
3715e41f4b71Sopenharmony_ci| ---------------------------------- | ---- | ----------------- |
3716e41f4b71Sopenharmony_ci| COMPRESS_LEVEL_NO_COMPRESSION      | 0    | 压缩率为0压缩等级。 |
3717e41f4b71Sopenharmony_ci| COMPRESS_LEVEL_BEST_SPEED          | 1    | 最佳速度压缩等级。  |
3718e41f4b71Sopenharmony_ci| COMPRESS_LEVEL_BEST_COMPRESSION    | 9    | 最佳压缩等级。      |
3719e41f4b71Sopenharmony_ci| COMPRESS_LEVEL_DEFAULT_COMPRESSION | -1   | 默认压缩等级。      |
3720e41f4b71Sopenharmony_ci
3721e41f4b71Sopenharmony_ci## zip.MemLevel
3722e41f4b71Sopenharmony_ci
3723e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3724e41f4b71Sopenharmony_ci
3725e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3726e41f4b71Sopenharmony_ci
3727e41f4b71Sopenharmony_ci| 名称              | 值   | 说明                             |
3728e41f4b71Sopenharmony_ci| ----------------- | ---- | -------------------------------- |
3729e41f4b71Sopenharmony_ci| MEM_LEVEL_MIN     | 1    | zip 接口在压缩过程中最小使用内存。 |
3730e41f4b71Sopenharmony_ci| MEM_LEVEL_MAX     | 9    | zip 接口在压缩过程中最大使用内存。 |
3731e41f4b71Sopenharmony_ci| MEM_LEVEL_DEFAULT | 8    | zip 接口在压缩过程中默认使用内存。 |
3732e41f4b71Sopenharmony_ci
3733e41f4b71Sopenharmony_ci## zip.CompressStrategy
3734e41f4b71Sopenharmony_ci
3735e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
3736e41f4b71Sopenharmony_ci
3737e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3738e41f4b71Sopenharmony_ci
3739e41f4b71Sopenharmony_ci| 名称                               | 值   | 说明                     |
3740e41f4b71Sopenharmony_ci| ---------------------------------- | ---- | ------------------------ |
3741e41f4b71Sopenharmony_ci| COMPRESS_STRATEGY_DEFAULT_STRATEGY | 0    | 常规数据策略。             |
3742e41f4b71Sopenharmony_ci| COMPRESS_STRATEGY_FILTERED         | 1    | 过滤器产生的数据压缩策略。 |
3743e41f4b71Sopenharmony_ci| COMPRESS_STRATEGY_HUFFMAN_ONLY     | 2    | 霍夫曼编码格式压缩策略。   |
3744e41f4b71Sopenharmony_ci| COMPRESS_STRATEGY_RLE              | 3    | 游标编码压缩策略。         |
3745e41f4b71Sopenharmony_ci| COMPRESS_STRATEGY_FIXED            | 4    | 固定的压缩策略。           |
3746e41f4b71Sopenharmony_ci
3747e41f4b71Sopenharmony_ci## zip.ErrorCode
3748e41f4b71Sopenharmony_ci
3749e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3750e41f4b71Sopenharmony_ci
3751e41f4b71Sopenharmony_ci| 名称             | 值   | 说明         |
3752e41f4b71Sopenharmony_ci| ---------------- | ---- | ------------ |
3753e41f4b71Sopenharmony_ci| ERROR_CODE_OK    | 0    | 函数调用成功。 |
3754e41f4b71Sopenharmony_ci| ERROR_CODE_ERRNO | -1   | 函数调用失败。 |
3755e41f4b71Sopenharmony_ci
3756e41f4b71Sopenharmony_ci## zip.CompressFlushMode<sup>12+</sup>
3757e41f4b71Sopenharmony_ci
3758e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3759e41f4b71Sopenharmony_ci
3760e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3761e41f4b71Sopenharmony_ci
3762e41f4b71Sopenharmony_ci| 名称          | 值   | 说明                                         |
3763e41f4b71Sopenharmony_ci| ------------- | ---- | -------------------------------------------- |
3764e41f4b71Sopenharmony_ci| NO_FLUSH      | 0    | 默认值,表示正常操作。                       |
3765e41f4b71Sopenharmony_ci| PARTIAL_FLUSH | 1    | 在流中生成部分刷新点。                       |
3766e41f4b71Sopenharmony_ci| SYNC_FLUSH    | 2    | 在保持压缩流状态的同时强制输出所有压缩数据。 |
3767e41f4b71Sopenharmony_ci| FULL_FLUSH    | 3    | 重置压缩状态。                               |
3768e41f4b71Sopenharmony_ci| FINISH        | 4    | 压缩或解压缩过程结束。                       |
3769e41f4b71Sopenharmony_ci| BLOCK         | 5    | 允许更精确的控制。                           |
3770e41f4b71Sopenharmony_ci| TREES         | 6    | 实施过程中有特殊目的。                       |
3771e41f4b71Sopenharmony_ci
3772e41f4b71Sopenharmony_ci## zip.CompressMethod<sup>12+</sup>
3773e41f4b71Sopenharmony_ci
3774e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3775e41f4b71Sopenharmony_ci
3776e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3777e41f4b71Sopenharmony_ci
3778e41f4b71Sopenharmony_ci| 名称     | 值   | 说明       |
3779e41f4b71Sopenharmony_ci| -------- | ---- | ---------- |
3780e41f4b71Sopenharmony_ci| DEFLATED | 8    | 压缩方法。 |
3781e41f4b71Sopenharmony_ci
3782e41f4b71Sopenharmony_ci## zip.ReturnStatus<sup>12+</sup>
3783e41f4b71Sopenharmony_ci
3784e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3785e41f4b71Sopenharmony_ci
3786e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3787e41f4b71Sopenharmony_ci
3788e41f4b71Sopenharmony_ci| 名称       | 值   | 说明                                           |
3789e41f4b71Sopenharmony_ci| ---------- | ---- | ---------------------------------------------- |
3790e41f4b71Sopenharmony_ci| OK         | 0    | 函数调用成功。                                 |
3791e41f4b71Sopenharmony_ci| STREAM_END | 1    | 函数调用成功,表示已处理了整个数据。           |
3792e41f4b71Sopenharmony_ci| NEED_DICT  | 2    | 函数调用成功,表示需要预设字典才能继续解压缩。 |
3793e41f4b71Sopenharmony_ci
3794e41f4b71Sopenharmony_ci## ZStream<sup>12+</sup>
3795e41f4b71Sopenharmony_ci
3796e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3797e41f4b71Sopenharmony_ci
3798e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3799e41f4b71Sopenharmony_ci
3800e41f4b71Sopenharmony_ci| 名称         | 类型        | 可读 | 可写 | 说明                                                         |
3801e41f4b71Sopenharmony_ci| ------------ | ----------- | ---- | ---- | ------------------------------------------------------------ |
3802e41f4b71Sopenharmony_ci| nextIn       | ArrayBuffer | 是   | 否   | 需要压缩的输入字节                                           |
3803e41f4b71Sopenharmony_ci| availableIn  | number      | 是   | 否   | nextIn可用的字节数                                           |
3804e41f4b71Sopenharmony_ci| totalIn      | number      | 是   | 否   | 到目前为止读取的输入字节总数                                 |
3805e41f4b71Sopenharmony_ci| nextOut      | ArrayBuffer | 是   | 否   | 压缩后的输出字节                                             |
3806e41f4b71Sopenharmony_ci| availableOut | number      | 是   | 否   | nextOut的剩余可用字节数                                      |
3807e41f4b71Sopenharmony_ci| totalOut     | number      | 是   | 否   | 到目前为止输出字节总数                                       |
3808e41f4b71Sopenharmony_ci| dataType     | number      | 是   | 否   | 关于数据类型的最佳猜测:deflate的二进制或文本,或inflate的解码状态 |
3809e41f4b71Sopenharmony_ci| adler        | number      | 是   | 否   | 未压缩数据的Adler-32或CRC-32值                               |
3810e41f4b71Sopenharmony_ci
3811e41f4b71Sopenharmony_ci## ZipOutputInfo<sup>12+</sup>
3812e41f4b71Sopenharmony_ci
3813e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3814e41f4b71Sopenharmony_ci
3815e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3816e41f4b71Sopenharmony_ci
3817e41f4b71Sopenharmony_ci| 名称    | 类型         | 可读 | 可写 | 说明                                                  |
3818e41f4b71Sopenharmony_ci| ------- | ------------ | ---- | ---- | ----------------------------------------------------- |
3819e41f4b71Sopenharmony_ci| status  | ReturnStatus | 是   | 否   | 参考[zlib.ReturnStatus枚举定义](#zipreturnstatus12)。 |
3820e41f4b71Sopenharmony_ci| destLen | number       | 是   | 否   | 目标缓冲区的总长度。                                  |
3821e41f4b71Sopenharmony_ci
3822e41f4b71Sopenharmony_ci## DictionaryOutputInfo<sup>12+</sup>
3823e41f4b71Sopenharmony_ci
3824e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3825e41f4b71Sopenharmony_ci
3826e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3827e41f4b71Sopenharmony_ci
3828e41f4b71Sopenharmony_ci| 名称             | 类型         | 可读 | 可写 | 说明                                                  |
3829e41f4b71Sopenharmony_ci| ---------------- | ------------ | ---- | ---- | ----------------------------------------------------- |
3830e41f4b71Sopenharmony_ci| status           | ReturnStatus | 是   | 否   | 参考[zlib.ReturnStatus枚举定义](#zipreturnstatus12)。 |
3831e41f4b71Sopenharmony_ci| dictionaryLength | number       | 是   | 否   | 字典的长度。                                          |
3832e41f4b71Sopenharmony_ci
3833e41f4b71Sopenharmony_ci## DecompressionOutputInfo<sup>12+</sup>
3834e41f4b71Sopenharmony_ci
3835e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3836e41f4b71Sopenharmony_ci
3837e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3838e41f4b71Sopenharmony_ci
3839e41f4b71Sopenharmony_ci| 名称             | 类型         | 可读 | 可写 | 说明                                                  |
3840e41f4b71Sopenharmony_ci| ---------------- | ------------ | ---- | ---- | ----------------------------------------------------- |
3841e41f4b71Sopenharmony_ci| status           | ReturnStatus | 是   | 否   | 参考[zlib.ReturnStatus枚举定义](#zipreturnstatus12)。 |
3842e41f4b71Sopenharmony_ci| destLength       | number       | 是   | 否   | 目标缓冲区的长度。                                     |
3843e41f4b71Sopenharmony_ci| sourceLength     | number       | 是   | 否   | 源缓冲区的长度。                                       |
3844e41f4b71Sopenharmony_ci
3845e41f4b71Sopenharmony_ci## DeflatePendingOutputInfo<sup>12+</sup>
3846e41f4b71Sopenharmony_ci
3847e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3848e41f4b71Sopenharmony_ci
3849e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3850e41f4b71Sopenharmony_ci
3851e41f4b71Sopenharmony_ci| 名称    | 类型         | 可读 | 可写 | 说明                                                  |
3852e41f4b71Sopenharmony_ci| ------- | ------------ | ---- | ---- | ----------------------------------------------------- |
3853e41f4b71Sopenharmony_ci| status  | ReturnStatus | 是   | 否   | 参考[zlib.ReturnStatus枚举定义](#zipreturnstatus12)。 |
3854e41f4b71Sopenharmony_ci| pending | number       | 是   | 否   | 已生成的输出字节数。                                  |
3855e41f4b71Sopenharmony_ci| bits    | number       | 是   | 否   | 已生成的输出位数。                                    |
3856e41f4b71Sopenharmony_ci
3857e41f4b71Sopenharmony_ci## GzHeader<sup>12+</sup>
3858e41f4b71Sopenharmony_ci
3859e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3860e41f4b71Sopenharmony_ci
3861e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3862e41f4b71Sopenharmony_ci
3863e41f4b71Sopenharmony_ci| 名称     | 类型        | 可读 | 可写 | 说明                                 |
3864e41f4b71Sopenharmony_ci| -------- | ----------- | ---- | ---- | ------------------------------------ |
3865e41f4b71Sopenharmony_ci| isText   | boolean     | 是   | 否   | 如果压缩数据被认为是文本,则为True。 |
3866e41f4b71Sopenharmony_ci| os       | number      | 是   | 否   | 操作系统。                           |
3867e41f4b71Sopenharmony_ci| time     | number      | 是   | 否   | 修改时间。                           |
3868e41f4b71Sopenharmony_ci| xflags   | number      | 是   | 否   | 额外标志。                           |
3869e41f4b71Sopenharmony_ci| extra    | ArrayBuffer | 是   | 否   | 额外字段。                           |
3870e41f4b71Sopenharmony_ci| extraLen | number      | 是   | 否   | 额外字段的长度。                     |
3871e41f4b71Sopenharmony_ci| name     | ArrayBuffer | 是   | 否   | 文件名。                             |
3872e41f4b71Sopenharmony_ci| comment  | ArrayBuffer | 是   | 否   | 注释。                               |
3873e41f4b71Sopenharmony_ci| hcrc     | boolean     | 是   | 否   | 如果存在crc标头,则为True。          |
3874e41f4b71Sopenharmony_ci| done     | boolean     | 是   | 否   | 读取gzip标头后为True。               |
3875e41f4b71Sopenharmony_ci
3876e41f4b71Sopenharmony_ci## zlib.createGZip<sup>12+</sup>
3877e41f4b71Sopenharmony_ci
3878e41f4b71Sopenharmony_cicreateGZip(): Promise&lt;GZip&gt;
3879e41f4b71Sopenharmony_ci
3880e41f4b71Sopenharmony_ci创建GZip对象,使用Promise异步返回。成功时返回Gzip对象实例。
3881e41f4b71Sopenharmony_ci
3882e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3883e41f4b71Sopenharmony_ci
3884e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3885e41f4b71Sopenharmony_ci
3886e41f4b71Sopenharmony_ci**返回值:**
3887e41f4b71Sopenharmony_ci
3888e41f4b71Sopenharmony_ci| 类型                           | 说明                            |
3889e41f4b71Sopenharmony_ci| ------------------------------ | ------------------------------- |
3890e41f4b71Sopenharmony_ci| Promise&lt;[GZip](#gzip12)&gt; | Promise对象。返回GZip对象实例。 |
3891e41f4b71Sopenharmony_ci
3892e41f4b71Sopenharmony_ci**示例:**
3893e41f4b71Sopenharmony_ci
3894e41f4b71Sopenharmony_ci```ts
3895e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
3896e41f4b71Sopenharmony_ci
3897e41f4b71Sopenharmony_cizlib.createGZip().then((data) => {
3898e41f4b71Sopenharmony_ci  console.info('createGZip success');
3899e41f4b71Sopenharmony_ci})
3900e41f4b71Sopenharmony_ci```
3901e41f4b71Sopenharmony_ci
3902e41f4b71Sopenharmony_ci## zlib.createGZipSync<sup>12+</sup>
3903e41f4b71Sopenharmony_ci
3904e41f4b71Sopenharmony_cicreateGZipSync():  GZip
3905e41f4b71Sopenharmony_ci
3906e41f4b71Sopenharmony_ci创建GZip对象。成功时返回GZip对象实例。
3907e41f4b71Sopenharmony_ci
3908e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3909e41f4b71Sopenharmony_ci
3910e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3911e41f4b71Sopenharmony_ci
3912e41f4b71Sopenharmony_ci**返回值:**
3913e41f4b71Sopenharmony_ci
3914e41f4b71Sopenharmony_ci| 类型            | 说明           |
3915e41f4b71Sopenharmony_ci| --------------- | -------------- |
3916e41f4b71Sopenharmony_ci| [GZip](#gzip12) | GZip对象实例。 |
3917e41f4b71Sopenharmony_ci
3918e41f4b71Sopenharmony_ci**示例:**
3919e41f4b71Sopenharmony_ci
3920e41f4b71Sopenharmony_ci```ts
3921e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
3922e41f4b71Sopenharmony_ci
3923e41f4b71Sopenharmony_cilet gzip = zlib.createGZipSync();
3924e41f4b71Sopenharmony_ci```
3925e41f4b71Sopenharmony_ci
3926e41f4b71Sopenharmony_ci## GZip<sup>12+</sup>
3927e41f4b71Sopenharmony_ci
3928e41f4b71Sopenharmony_ciGzip相关接口。
3929e41f4b71Sopenharmony_ci
3930e41f4b71Sopenharmony_ci### gzdopen<sup>12+</sup>
3931e41f4b71Sopenharmony_ci
3932e41f4b71Sopenharmony_cigzdopen(fd: number, mode: string): Promise&lt;void&gt;
3933e41f4b71Sopenharmony_ci
3934e41f4b71Sopenharmony_ci将gzFile与文件描述符fd相关联,打开文件,用于进行读取并解压缩,或者压缩并写入。
3935e41f4b71Sopenharmony_ci
3936e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3937e41f4b71Sopenharmony_ci
3938e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
3939e41f4b71Sopenharmony_ci
3940e41f4b71Sopenharmony_ci**参数:**
3941e41f4b71Sopenharmony_ci
3942e41f4b71Sopenharmony_ci| 参数名 | 类型   | 必填 | 说明                                                         |
3943e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
3944e41f4b71Sopenharmony_ci| fd     | number | 是   | 文件描述符。通常情况下,通过系统调用“open”或其他方法获得的。 |
3945e41f4b71Sopenharmony_ci| mode   | string | 是   | 用于指定访问模式。                                           |
3946e41f4b71Sopenharmony_ci
3947e41f4b71Sopenharmony_ci**返回值:**
3948e41f4b71Sopenharmony_ci
3949e41f4b71Sopenharmony_ci| 类型                | 说明                    |
3950e41f4b71Sopenharmony_ci| ------------------- | ----------------------- |
3951e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise对象,无返回值。 |
3952e41f4b71Sopenharmony_ci
3953e41f4b71Sopenharmony_ci**错误码:**
3954e41f4b71Sopenharmony_ci
3955e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
3956e41f4b71Sopenharmony_ci
3957e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3958e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3959e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
3960e41f4b71Sopenharmony_ci| 17800002 | No such file or access mode error.                           |
3961e41f4b71Sopenharmony_ci
3962e41f4b71Sopenharmony_ci**示例:**
3963e41f4b71Sopenharmony_ci
3964e41f4b71Sopenharmony_ci```ts
3965e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
3966e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
3967e41f4b71Sopenharmony_ci
3968e41f4b71Sopenharmony_ciasync function gzdopenDemo(pathDir: string) {
3969e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzdopen");
3970e41f4b71Sopenharmony_ci  let path = pathDir + "/gzdopen/test.gz";
3971e41f4b71Sopenharmony_ci  let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
3972e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
3973e41f4b71Sopenharmony_ci  await gzip.gzdopen(file.fd, "wb");
3974e41f4b71Sopenharmony_ci  await gzip.gzclose();
3975e41f4b71Sopenharmony_ci}
3976e41f4b71Sopenharmony_ci
3977e41f4b71Sopenharmony_ci@Entry
3978e41f4b71Sopenharmony_ci@Component
3979e41f4b71Sopenharmony_cistruct Index {
3980e41f4b71Sopenharmony_ci  build() {
3981e41f4b71Sopenharmony_ci    Row() {
3982e41f4b71Sopenharmony_ci      Column() {
3983e41f4b71Sopenharmony_ci        Button('test gzip interface')
3984e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
3985e41f4b71Sopenharmony_ci          .height(60)
3986e41f4b71Sopenharmony_ci          .width(200)
3987e41f4b71Sopenharmony_ci          .onClick(() => {
3988e41f4b71Sopenharmony_ci            let context = getContext(this);
3989e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
3990e41f4b71Sopenharmony_ci            gzdopenDemo(pathDir);
3991e41f4b71Sopenharmony_ci          })
3992e41f4b71Sopenharmony_ci      }
3993e41f4b71Sopenharmony_ci      .width('100%')
3994e41f4b71Sopenharmony_ci    }
3995e41f4b71Sopenharmony_ci    .height('100%')
3996e41f4b71Sopenharmony_ci  }
3997e41f4b71Sopenharmony_ci}
3998e41f4b71Sopenharmony_ci```
3999e41f4b71Sopenharmony_ci
4000e41f4b71Sopenharmony_ci### gzbuffer<sup>12+</sup>
4001e41f4b71Sopenharmony_ci
4002e41f4b71Sopenharmony_cigzbuffer(size: number):Promise&lt;number&gt;
4003e41f4b71Sopenharmony_ci
4004e41f4b71Sopenharmony_ci为当前库函数设置内部缓冲区尺寸。
4005e41f4b71Sopenharmony_ci
4006e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4007e41f4b71Sopenharmony_ci
4008e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4009e41f4b71Sopenharmony_ci
4010e41f4b71Sopenharmony_ci**参数:**
4011e41f4b71Sopenharmony_ci
4012e41f4b71Sopenharmony_ci| 参数名 | 类型   | 必填 | 说明                       |
4013e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------- |
4014e41f4b71Sopenharmony_ci| size   | number | 是   | 需要设置的内部缓冲区尺寸。 |
4015e41f4b71Sopenharmony_ci
4016e41f4b71Sopenharmony_ci**返回值:**
4017e41f4b71Sopenharmony_ci
4018e41f4b71Sopenharmony_ci| 类型                  | 说明                         |
4019e41f4b71Sopenharmony_ci| --------------------- | ---------------------------- |
4020e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,成功时,返回0。 |
4021e41f4b71Sopenharmony_ci
4022e41f4b71Sopenharmony_ci**错误码:**
4023e41f4b71Sopenharmony_ci
4024e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4025e41f4b71Sopenharmony_ci
4026e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
4027e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
4028e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
4029e41f4b71Sopenharmony_ci| 17800009   | Internal structure error. |
4030e41f4b71Sopenharmony_ci
4031e41f4b71Sopenharmony_ci**示例:**
4032e41f4b71Sopenharmony_ci
4033e41f4b71Sopenharmony_ci```ts
4034e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4035e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit'
4036e41f4b71Sopenharmony_ci
4037e41f4b71Sopenharmony_ciasync function gzbufferDemo(pathDir: string) {
4038e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzbuffer");
4039e41f4b71Sopenharmony_ci  let path = pathDir + "/gzbuffer/test.gz";
4040e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4041e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4042e41f4b71Sopenharmony_ci  await gzip.gzclose();
4043e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "rb");
4044e41f4b71Sopenharmony_ci  let result = await gzip.gzbuffer(648);
4045e41f4b71Sopenharmony_ci  await gzip.gzclose();
4046e41f4b71Sopenharmony_ci}
4047e41f4b71Sopenharmony_ci
4048e41f4b71Sopenharmony_ci@Entry
4049e41f4b71Sopenharmony_ci@Component
4050e41f4b71Sopenharmony_cistruct Index {
4051e41f4b71Sopenharmony_ci  build() {
4052e41f4b71Sopenharmony_ci    Row() {
4053e41f4b71Sopenharmony_ci      Column() {
4054e41f4b71Sopenharmony_ci        Button('test gzip interface')
4055e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4056e41f4b71Sopenharmony_ci          .height(60)
4057e41f4b71Sopenharmony_ci          .width(200)
4058e41f4b71Sopenharmony_ci          .onClick(() => {
4059e41f4b71Sopenharmony_ci            let context = getContext(this);
4060e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4061e41f4b71Sopenharmony_ci            gzbufferDemo(pathDir);
4062e41f4b71Sopenharmony_ci          })
4063e41f4b71Sopenharmony_ci      }
4064e41f4b71Sopenharmony_ci      .width('100%')
4065e41f4b71Sopenharmony_ci    }
4066e41f4b71Sopenharmony_ci    .height('100%')
4067e41f4b71Sopenharmony_ci  }
4068e41f4b71Sopenharmony_ci}
4069e41f4b71Sopenharmony_ci```
4070e41f4b71Sopenharmony_ci
4071e41f4b71Sopenharmony_ci### gzopen<sup>12+</sup>
4072e41f4b71Sopenharmony_ci
4073e41f4b71Sopenharmony_cigzopen(path: string, mode: string): Promise&lt;void&gt;
4074e41f4b71Sopenharmony_ci
4075e41f4b71Sopenharmony_ci打开位于指定路径的gzip(.gz)文件,用于进行读取并解压缩,或者压缩并写入。
4076e41f4b71Sopenharmony_ci
4077e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4078e41f4b71Sopenharmony_ci
4079e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4080e41f4b71Sopenharmony_ci
4081e41f4b71Sopenharmony_ci**参数:**
4082e41f4b71Sopenharmony_ci
4083e41f4b71Sopenharmony_ci| 参数名 | 类型   | 必填 | 说明                 |
4084e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------- |
4085e41f4b71Sopenharmony_ci| path   | string | 是   | 需要打开的文件路径。 |
4086e41f4b71Sopenharmony_ci| mode   | string | 是   | 指定文件打开方法。   |
4087e41f4b71Sopenharmony_ci
4088e41f4b71Sopenharmony_ci**返回值:**
4089e41f4b71Sopenharmony_ci
4090e41f4b71Sopenharmony_ci| 类型                | 说明                    |
4091e41f4b71Sopenharmony_ci| ------------------- | ----------------------- |
4092e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise对象,无返回值。 |
4093e41f4b71Sopenharmony_ci
4094e41f4b71Sopenharmony_ci**错误码:**
4095e41f4b71Sopenharmony_ci
4096e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
4097e41f4b71Sopenharmony_ci
4098e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
4099e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
4100e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
4101e41f4b71Sopenharmony_ci| 17800002 | No such file or access mode error.                           |
4102e41f4b71Sopenharmony_ci
4103e41f4b71Sopenharmony_ci**示例:**
4104e41f4b71Sopenharmony_ci
4105e41f4b71Sopenharmony_ci```ts
4106e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4107e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4108e41f4b71Sopenharmony_ci
4109e41f4b71Sopenharmony_ciasync function gzopenDemo(pathDir: string) {
4110e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzopen");
4111e41f4b71Sopenharmony_ci  let path = pathDir + "/gzopen/test.gz";
4112e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4113e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4114e41f4b71Sopenharmony_ci  await gzip.gzclose();
4115e41f4b71Sopenharmony_ci}
4116e41f4b71Sopenharmony_ci
4117e41f4b71Sopenharmony_ci@Entry
4118e41f4b71Sopenharmony_ci@Component
4119e41f4b71Sopenharmony_cistruct Index {
4120e41f4b71Sopenharmony_ci  build() {
4121e41f4b71Sopenharmony_ci    Row() {
4122e41f4b71Sopenharmony_ci      Column() {
4123e41f4b71Sopenharmony_ci        Button('test gzip interface')
4124e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4125e41f4b71Sopenharmony_ci          .height(60)
4126e41f4b71Sopenharmony_ci          .width(200)
4127e41f4b71Sopenharmony_ci          .onClick(() => {
4128e41f4b71Sopenharmony_ci            let context = getContext(this);
4129e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4130e41f4b71Sopenharmony_ci            gzopenDemo(pathDir);
4131e41f4b71Sopenharmony_ci          })
4132e41f4b71Sopenharmony_ci      }
4133e41f4b71Sopenharmony_ci      .width('100%')
4134e41f4b71Sopenharmony_ci    }
4135e41f4b71Sopenharmony_ci    .height('100%')
4136e41f4b71Sopenharmony_ci  }
4137e41f4b71Sopenharmony_ci}
4138e41f4b71Sopenharmony_ci```
4139e41f4b71Sopenharmony_ci
4140e41f4b71Sopenharmony_ci### gzeof<sup>12+</sup>
4141e41f4b71Sopenharmony_ci
4142e41f4b71Sopenharmony_cigzeof(): Promise&lt;number&gt;
4143e41f4b71Sopenharmony_ci
4144e41f4b71Sopenharmony_ci检查gzip压缩文件的读取位置是否已到达文件的末尾。
4145e41f4b71Sopenharmony_ci
4146e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4147e41f4b71Sopenharmony_ci
4148e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4149e41f4b71Sopenharmony_ci
4150e41f4b71Sopenharmony_ci**返回值:**
4151e41f4b71Sopenharmony_ci
4152e41f4b71Sopenharmony_ci| 类型                  | 说明                                                         |
4153e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------------------------------ |
4154e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,如果在读取时设置了文件的文件结束指示符,则返回1。 |
4155e41f4b71Sopenharmony_ci
4156e41f4b71Sopenharmony_ci**示例:**
4157e41f4b71Sopenharmony_ci
4158e41f4b71Sopenharmony_ci```ts
4159e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4160e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4161e41f4b71Sopenharmony_ci
4162e41f4b71Sopenharmony_ciasync function gzeofDemo(pathDir: string) {
4163e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzeof");
4164e41f4b71Sopenharmony_ci  let path = pathDir + "/gzeof/test.gz";
4165e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4166e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4167e41f4b71Sopenharmony_ci  let writeBufferWithData = new ArrayBuffer(16);
4168e41f4b71Sopenharmony_ci  let uint8View = new Uint8Array(writeBufferWithData);
4169e41f4b71Sopenharmony_ci  for (let i = 0; i < uint8View.length; i++) {
4170e41f4b71Sopenharmony_ci    uint8View[i] = i;
4171e41f4b71Sopenharmony_ci  }
4172e41f4b71Sopenharmony_ci  let writeNum = await gzip.gzwrite(writeBufferWithData, 16)
4173e41f4b71Sopenharmony_ci  await gzip.gzclose();
4174e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "rb");
4175e41f4b71Sopenharmony_ci  let readBufferWithData = new ArrayBuffer(20);
4176e41f4b71Sopenharmony_ci  let readNum = await gzip.gzread(readBufferWithData);
4177e41f4b71Sopenharmony_ci  let eofNum = await gzip.gzeof();
4178e41f4b71Sopenharmony_ci  await gzip.gzclose();
4179e41f4b71Sopenharmony_ci}
4180e41f4b71Sopenharmony_ci
4181e41f4b71Sopenharmony_ci@Entry
4182e41f4b71Sopenharmony_ci@Component
4183e41f4b71Sopenharmony_cistruct Index {
4184e41f4b71Sopenharmony_ci  build() {
4185e41f4b71Sopenharmony_ci    Row() {
4186e41f4b71Sopenharmony_ci      Column() {
4187e41f4b71Sopenharmony_ci        Button('test gzip interface')
4188e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4189e41f4b71Sopenharmony_ci          .height(60)
4190e41f4b71Sopenharmony_ci          .width(200)
4191e41f4b71Sopenharmony_ci          .onClick(() => {
4192e41f4b71Sopenharmony_ci            let context = getContext(this);
4193e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4194e41f4b71Sopenharmony_ci            gzeofDemo(pathDir);
4195e41f4b71Sopenharmony_ci          })
4196e41f4b71Sopenharmony_ci      }
4197e41f4b71Sopenharmony_ci      .width('100%')
4198e41f4b71Sopenharmony_ci    }
4199e41f4b71Sopenharmony_ci    .height('100%')
4200e41f4b71Sopenharmony_ci  }
4201e41f4b71Sopenharmony_ci}
4202e41f4b71Sopenharmony_ci```
4203e41f4b71Sopenharmony_ci
4204e41f4b71Sopenharmony_ci### gzdirect<sup>12+</sup>
4205e41f4b71Sopenharmony_ci
4206e41f4b71Sopenharmony_cigzdirect(): Promise&lt;number&gt;
4207e41f4b71Sopenharmony_ci
4208e41f4b71Sopenharmony_ci检查指定的gzip文件句柄文件是否直接访问原始未压缩数据,重新分配缓冲区。
4209e41f4b71Sopenharmony_ci
4210e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4211e41f4b71Sopenharmony_ci
4212e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4213e41f4b71Sopenharmony_ci
4214e41f4b71Sopenharmony_ci**返回值:**
4215e41f4b71Sopenharmony_ci
4216e41f4b71Sopenharmony_ci| 类型                  | 说明                                               |
4217e41f4b71Sopenharmony_ci| --------------------- | -------------------------------------------------- |
4218e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,如果直接访问原始未压缩数据,则返回1。 |
4219e41f4b71Sopenharmony_ci
4220e41f4b71Sopenharmony_ci**示例:**
4221e41f4b71Sopenharmony_ci
4222e41f4b71Sopenharmony_ci```ts
4223e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4224e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4225e41f4b71Sopenharmony_ci
4226e41f4b71Sopenharmony_ciasync function gzdirectDemo(pathDir: string) {
4227e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzdirect");
4228e41f4b71Sopenharmony_ci  let path = pathDir + "/gzdirect/test.gz";
4229e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4230e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4231e41f4b71Sopenharmony_ci  let directNum = await gzip.gzdirect();
4232e41f4b71Sopenharmony_ci  await gzip.gzclose();
4233e41f4b71Sopenharmony_ci}
4234e41f4b71Sopenharmony_ci
4235e41f4b71Sopenharmony_ci@Entry
4236e41f4b71Sopenharmony_ci@Component
4237e41f4b71Sopenharmony_cistruct Index {
4238e41f4b71Sopenharmony_ci  build() {
4239e41f4b71Sopenharmony_ci    Row() {
4240e41f4b71Sopenharmony_ci      Column() {
4241e41f4b71Sopenharmony_ci        Button('test gzip interface')
4242e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4243e41f4b71Sopenharmony_ci          .height(60)
4244e41f4b71Sopenharmony_ci          .width(200)
4245e41f4b71Sopenharmony_ci          .onClick(() => {
4246e41f4b71Sopenharmony_ci            let context = getContext(this);
4247e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4248e41f4b71Sopenharmony_ci            gzdirectDemo(pathDir);
4249e41f4b71Sopenharmony_ci          })
4250e41f4b71Sopenharmony_ci      }
4251e41f4b71Sopenharmony_ci      .width('100%')
4252e41f4b71Sopenharmony_ci    }
4253e41f4b71Sopenharmony_ci    .height('100%')
4254e41f4b71Sopenharmony_ci  }
4255e41f4b71Sopenharmony_ci}
4256e41f4b71Sopenharmony_ci```
4257e41f4b71Sopenharmony_ci
4258e41f4b71Sopenharmony_ci### gzclose<sup>12+</sup>
4259e41f4b71Sopenharmony_ci
4260e41f4b71Sopenharmony_cigzclose(): Promise&lt;ReturnStatus&gt;
4261e41f4b71Sopenharmony_ci
4262e41f4b71Sopenharmony_ci清除文件的所有挂起输出,如有必要,关闭文件和释放(解)压缩状态。
4263e41f4b71Sopenharmony_ci
4264e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4265e41f4b71Sopenharmony_ci
4266e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4267e41f4b71Sopenharmony_ci
4268e41f4b71Sopenharmony_ci**返回值:**
4269e41f4b71Sopenharmony_ci
4270e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
4271e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
4272e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象,返回结果状态。 |
4273e41f4b71Sopenharmony_ci
4274e41f4b71Sopenharmony_ci**错误码:**
4275e41f4b71Sopenharmony_ci
4276e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.zlib错误码](./errorcode-zlib.md)。
4277e41f4b71Sopenharmony_ci
4278e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
4279e41f4b71Sopenharmony_ci| -------- | ------------------------- |
4280e41f4b71Sopenharmony_ci| 17800004 | ZStream error.            |
4281e41f4b71Sopenharmony_ci| 17800006 | Memory allocation failed. |
4282e41f4b71Sopenharmony_ci
4283e41f4b71Sopenharmony_ci**示例:**
4284e41f4b71Sopenharmony_ci
4285e41f4b71Sopenharmony_ci```ts
4286e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4287e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4288e41f4b71Sopenharmony_ci
4289e41f4b71Sopenharmony_ciasync function gzcloseDemo(pathDir: string) {
4290e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzclose");
4291e41f4b71Sopenharmony_ci  let path = pathDir + "/gzclose/test.gz";
4292e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4293e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4294e41f4b71Sopenharmony_ci  await gzip.gzclose();
4295e41f4b71Sopenharmony_ci}
4296e41f4b71Sopenharmony_ci
4297e41f4b71Sopenharmony_ci@Entry
4298e41f4b71Sopenharmony_ci@Component
4299e41f4b71Sopenharmony_cistruct Index {
4300e41f4b71Sopenharmony_ci  build() {
4301e41f4b71Sopenharmony_ci    Row() {
4302e41f4b71Sopenharmony_ci      Column() {
4303e41f4b71Sopenharmony_ci        Button('test gzip interface')
4304e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4305e41f4b71Sopenharmony_ci          .height(60)
4306e41f4b71Sopenharmony_ci          .width(200)
4307e41f4b71Sopenharmony_ci          .onClick(() => {
4308e41f4b71Sopenharmony_ci            let context = getContext(this);
4309e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4310e41f4b71Sopenharmony_ci            gzcloseDemo(pathDir);
4311e41f4b71Sopenharmony_ci          })
4312e41f4b71Sopenharmony_ci      }
4313e41f4b71Sopenharmony_ci      .width('100%')
4314e41f4b71Sopenharmony_ci    }
4315e41f4b71Sopenharmony_ci    .height('100%')
4316e41f4b71Sopenharmony_ci  }
4317e41f4b71Sopenharmony_ci}
4318e41f4b71Sopenharmony_ci```
4319e41f4b71Sopenharmony_ci
4320e41f4b71Sopenharmony_ci### gzclearerr<sup>12+</sup>
4321e41f4b71Sopenharmony_ci
4322e41f4b71Sopenharmony_cigzclearerr(): Promise&lt;void&gt;
4323e41f4b71Sopenharmony_ci
4324e41f4b71Sopenharmony_ci清除文件的错误和文件结束标志。
4325e41f4b71Sopenharmony_ci
4326e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4327e41f4b71Sopenharmony_ci
4328e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4329e41f4b71Sopenharmony_ci
4330e41f4b71Sopenharmony_ci**返回值:**
4331e41f4b71Sopenharmony_ci
4332e41f4b71Sopenharmony_ci| 类型                | 说明                    |
4333e41f4b71Sopenharmony_ci| ------------------- | ----------------------- |
4334e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise对象,无返回值。 |
4335e41f4b71Sopenharmony_ci
4336e41f4b71Sopenharmony_ci**示例:**
4337e41f4b71Sopenharmony_ci
4338e41f4b71Sopenharmony_ci```ts
4339e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4340e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4341e41f4b71Sopenharmony_ci
4342e41f4b71Sopenharmony_ciasync function gzclearerrDemo(pathDir: string) {
4343e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzclearerr");
4344e41f4b71Sopenharmony_ci  let path = pathDir + "/gzclearerr/test.gz";
4345e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4346e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4347e41f4b71Sopenharmony_ci  let writeBufferWithData = new ArrayBuffer(16);
4348e41f4b71Sopenharmony_ci  let uint8View = new Uint8Array(writeBufferWithData);
4349e41f4b71Sopenharmony_ci  for (let i = 0; i < uint8View.length; i++) {
4350e41f4b71Sopenharmony_ci    uint8View[i] = i;
4351e41f4b71Sopenharmony_ci  }
4352e41f4b71Sopenharmony_ci  let writeNum = await gzip.gzwrite(writeBufferWithData, 16)
4353e41f4b71Sopenharmony_ci  await gzip.gzclose();
4354e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "rb");
4355e41f4b71Sopenharmony_ci  let readBufferWithData = new ArrayBuffer(20);
4356e41f4b71Sopenharmony_ci  let readNum = await gzip.gzread(readBufferWithData);
4357e41f4b71Sopenharmony_ci  let eofNum = await gzip.gzeof();
4358e41f4b71Sopenharmony_ci  await gzip.gzclearerr();
4359e41f4b71Sopenharmony_ci  let eofNumClear = await gzip.gzeof();
4360e41f4b71Sopenharmony_ci  await gzip.gzclose();
4361e41f4b71Sopenharmony_ci}
4362e41f4b71Sopenharmony_ci
4363e41f4b71Sopenharmony_ci@Entry
4364e41f4b71Sopenharmony_ci@Component
4365e41f4b71Sopenharmony_cistruct Index {
4366e41f4b71Sopenharmony_ci  build() {
4367e41f4b71Sopenharmony_ci    Row() {
4368e41f4b71Sopenharmony_ci      Column() {
4369e41f4b71Sopenharmony_ci        Button('test gzip interface')
4370e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4371e41f4b71Sopenharmony_ci          .height(60)
4372e41f4b71Sopenharmony_ci          .width(200)
4373e41f4b71Sopenharmony_ci          .onClick(() => {
4374e41f4b71Sopenharmony_ci            let context = getContext(this);
4375e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4376e41f4b71Sopenharmony_ci            gzclearerrDemo(pathDir);
4377e41f4b71Sopenharmony_ci          })
4378e41f4b71Sopenharmony_ci      }
4379e41f4b71Sopenharmony_ci      .width('100%')
4380e41f4b71Sopenharmony_ci    }
4381e41f4b71Sopenharmony_ci    .height('100%')
4382e41f4b71Sopenharmony_ci  }
4383e41f4b71Sopenharmony_ci}
4384e41f4b71Sopenharmony_ci```
4385e41f4b71Sopenharmony_ci
4386e41f4b71Sopenharmony_ci### gzerror<sup>12+</sup>
4387e41f4b71Sopenharmony_ci
4388e41f4b71Sopenharmony_cigzerror(): Promise&lt;GzErrorOutputInfo&gt;
4389e41f4b71Sopenharmony_ci
4390e41f4b71Sopenharmony_ci文件上发生的最后一个错误的错误消息。
4391e41f4b71Sopenharmony_ci
4392e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4393e41f4b71Sopenharmony_ci
4394e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4395e41f4b71Sopenharmony_ci
4396e41f4b71Sopenharmony_ci**返回值:**
4397e41f4b71Sopenharmony_ci
4398e41f4b71Sopenharmony_ci| 类型                                                        | 说明                                                      |
4399e41f4b71Sopenharmony_ci| ----------------------------------------------------------- | --------------------------------------------------------- |
4400e41f4b71Sopenharmony_ci| Promise&lt;[GzErrorOutputInfo](#zipgzerroroutputinfo12)&gt; | Promise对象,返回结果状态和出现的最后一个状态的状态消息。 |
4401e41f4b71Sopenharmony_ci
4402e41f4b71Sopenharmony_ci**错误码:**
4403e41f4b71Sopenharmony_ci
4404e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.zlib错误码](./errorcode-zlib.md)。
4405e41f4b71Sopenharmony_ci
4406e41f4b71Sopenharmony_ci| 错误码ID | 错误信息       |
4407e41f4b71Sopenharmony_ci| -------- | -------------- |
4408e41f4b71Sopenharmony_ci| 17800004 | ZStream error. |
4409e41f4b71Sopenharmony_ci
4410e41f4b71Sopenharmony_ci**示例:**
4411e41f4b71Sopenharmony_ci
4412e41f4b71Sopenharmony_ci```ts
4413e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4414e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4415e41f4b71Sopenharmony_ci
4416e41f4b71Sopenharmony_ciasync function gzerrorDemo(pathDir: string) {
4417e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzerror");
4418e41f4b71Sopenharmony_ci  let path = pathDir + "/gzerror/test.gz";
4419e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4420e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4421e41f4b71Sopenharmony_ci  let writeBufferWithData = new ArrayBuffer(16);
4422e41f4b71Sopenharmony_ci  let uint8View = new Uint8Array(writeBufferWithData);
4423e41f4b71Sopenharmony_ci  for (let i = 0; i < uint8View.length; i++) {
4424e41f4b71Sopenharmony_ci    uint8View[i] = i;
4425e41f4b71Sopenharmony_ci  }
4426e41f4b71Sopenharmony_ci  try {
4427e41f4b71Sopenharmony_ci    await gzip.gzwrite(writeBufferWithData, -1);
4428e41f4b71Sopenharmony_ci  } catch (errData) {
4429e41f4b71Sopenharmony_ci    await gzip.gzerror().then((GzErrorOutputInfo) => {
4430e41f4b71Sopenharmony_ci      console.info('errCode', GzErrorOutputInfo.status);
4431e41f4b71Sopenharmony_ci      console.info('errMsg', GzErrorOutputInfo.statusMsg);
4432e41f4b71Sopenharmony_ci    })
4433e41f4b71Sopenharmony_ci  }
4434e41f4b71Sopenharmony_ci  await gzip.gzclose();
4435e41f4b71Sopenharmony_ci}
4436e41f4b71Sopenharmony_ci
4437e41f4b71Sopenharmony_ci@Entry
4438e41f4b71Sopenharmony_ci@Component
4439e41f4b71Sopenharmony_cistruct Index {
4440e41f4b71Sopenharmony_ci  build() {
4441e41f4b71Sopenharmony_ci    Row() {
4442e41f4b71Sopenharmony_ci      Column() {
4443e41f4b71Sopenharmony_ci        Button('test gzip interface')
4444e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4445e41f4b71Sopenharmony_ci          .height(60)
4446e41f4b71Sopenharmony_ci          .width(200)
4447e41f4b71Sopenharmony_ci          .onClick(() => {
4448e41f4b71Sopenharmony_ci            let context = getContext(this);
4449e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4450e41f4b71Sopenharmony_ci            gzerrorDemo(pathDir);
4451e41f4b71Sopenharmony_ci          })
4452e41f4b71Sopenharmony_ci      }
4453e41f4b71Sopenharmony_ci      .width('100%')
4454e41f4b71Sopenharmony_ci    }
4455e41f4b71Sopenharmony_ci    .height('100%')
4456e41f4b71Sopenharmony_ci  }
4457e41f4b71Sopenharmony_ci}
4458e41f4b71Sopenharmony_ci```
4459e41f4b71Sopenharmony_ci
4460e41f4b71Sopenharmony_ci### gzgetc<sup>12+</sup>
4461e41f4b71Sopenharmony_ci
4462e41f4b71Sopenharmony_cigzgetc(): Promise&lt;number&gt;
4463e41f4b71Sopenharmony_ci
4464e41f4b71Sopenharmony_ci从文件中读取并解压缩一个字节。
4465e41f4b71Sopenharmony_ci
4466e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4467e41f4b71Sopenharmony_ci
4468e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4469e41f4b71Sopenharmony_ci
4470e41f4b71Sopenharmony_ci**返回值:**
4471e41f4b71Sopenharmony_ci
4472e41f4b71Sopenharmony_ci| 类型                  | 说明                                 |
4473e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------ |
4474e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回读取字符的ASCII值。 |
4475e41f4b71Sopenharmony_ci
4476e41f4b71Sopenharmony_ci**错误码:**
4477e41f4b71Sopenharmony_ci
4478e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.zlib错误码](./errorcode-zlib.md)。
4479e41f4b71Sopenharmony_ci
4480e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
4481e41f4b71Sopenharmony_ci| -------- | ------------------------- |
4482e41f4b71Sopenharmony_ci| 17800009 | Internal structure error. |
4483e41f4b71Sopenharmony_ci
4484e41f4b71Sopenharmony_ci**示例:**
4485e41f4b71Sopenharmony_ci
4486e41f4b71Sopenharmony_ci```ts
4487e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4488e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4489e41f4b71Sopenharmony_ci
4490e41f4b71Sopenharmony_ciasync function gzgetcDemo(pathDir: string) {
4491e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzgetc");
4492e41f4b71Sopenharmony_ci  let path = pathDir + "/gzgetc/test.gz";
4493e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4494e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4495e41f4b71Sopenharmony_ci  await gzip.gzputc(1);
4496e41f4b71Sopenharmony_ci  await gzip.gzclose();
4497e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "rb");
4498e41f4b71Sopenharmony_ci  let resulit = await gzip.gzgetc();
4499e41f4b71Sopenharmony_ci  await gzip.gzclose();
4500e41f4b71Sopenharmony_ci}
4501e41f4b71Sopenharmony_ci
4502e41f4b71Sopenharmony_ci@Entry
4503e41f4b71Sopenharmony_ci@Component
4504e41f4b71Sopenharmony_cistruct Index {
4505e41f4b71Sopenharmony_ci  build() {
4506e41f4b71Sopenharmony_ci    Row() {
4507e41f4b71Sopenharmony_ci      Column() {
4508e41f4b71Sopenharmony_ci        Button('test gzip interface')
4509e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4510e41f4b71Sopenharmony_ci          .height(60)
4511e41f4b71Sopenharmony_ci          .width(200)
4512e41f4b71Sopenharmony_ci          .onClick(() => {
4513e41f4b71Sopenharmony_ci            let context = getContext(this);
4514e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4515e41f4b71Sopenharmony_ci            gzgetcDemo(pathDir);
4516e41f4b71Sopenharmony_ci          })
4517e41f4b71Sopenharmony_ci      }
4518e41f4b71Sopenharmony_ci      .width('100%')
4519e41f4b71Sopenharmony_ci    }
4520e41f4b71Sopenharmony_ci    .height('100%')
4521e41f4b71Sopenharmony_ci  }
4522e41f4b71Sopenharmony_ci}
4523e41f4b71Sopenharmony_ci```
4524e41f4b71Sopenharmony_ci
4525e41f4b71Sopenharmony_ci### gzflush<sup>12+</sup>
4526e41f4b71Sopenharmony_ci
4527e41f4b71Sopenharmony_cigzflush(flush: CompressFlushMode): Promise&lt;ReturnStatus&gt;
4528e41f4b71Sopenharmony_ci
4529e41f4b71Sopenharmony_ci将所有挂起的输出刷新到文件中。
4530e41f4b71Sopenharmony_ci
4531e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4532e41f4b71Sopenharmony_ci
4533e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4534e41f4b71Sopenharmony_ci
4535e41f4b71Sopenharmony_ci**参数:**
4536e41f4b71Sopenharmony_ci
4537e41f4b71Sopenharmony_ci| 参数名 | 类型              | 必填 | 说明                                                         |
4538e41f4b71Sopenharmony_ci| ------ | ----------------- | ---- | ------------------------------------------------------------ |
4539e41f4b71Sopenharmony_ci| flush  | CompressFlushMode | 是   | 控制刷新操作的行为,参考[CompressFlushMode枚举](#zipcompressflushmode12)的定义。 |
4540e41f4b71Sopenharmony_ci
4541e41f4b71Sopenharmony_ci**返回值:**
4542e41f4b71Sopenharmony_ci
4543e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
4544e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
4545e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象,返回结果状态。 |
4546e41f4b71Sopenharmony_ci
4547e41f4b71Sopenharmony_ci**错误码:**
4548e41f4b71Sopenharmony_ci
4549e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
4550e41f4b71Sopenharmony_ci
4551e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
4552e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
4553e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
4554e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
4555e41f4b71Sopenharmony_ci
4556e41f4b71Sopenharmony_ci**示例:**
4557e41f4b71Sopenharmony_ci
4558e41f4b71Sopenharmony_ci```ts
4559e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4560e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4561e41f4b71Sopenharmony_ci
4562e41f4b71Sopenharmony_ciasync function gzflushDemo(pathDir: string) {
4563e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzflush");
4564e41f4b71Sopenharmony_ci  let path = pathDir + "/gzflush/test.gz";
4565e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4566e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4567e41f4b71Sopenharmony_ci  let flushNum = await gzip.gzflush(zlib.CompressFlushMode.NO_FLUSH);
4568e41f4b71Sopenharmony_ci  await gzip.gzclose();
4569e41f4b71Sopenharmony_ci}
4570e41f4b71Sopenharmony_ci
4571e41f4b71Sopenharmony_ci@Entry
4572e41f4b71Sopenharmony_ci@Component
4573e41f4b71Sopenharmony_cistruct Index {
4574e41f4b71Sopenharmony_ci  build() {
4575e41f4b71Sopenharmony_ci    Row() {
4576e41f4b71Sopenharmony_ci      Column() {
4577e41f4b71Sopenharmony_ci        Button('test gzip interface')
4578e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4579e41f4b71Sopenharmony_ci          .height(60)
4580e41f4b71Sopenharmony_ci          .width(200)
4581e41f4b71Sopenharmony_ci          .onClick(() => {
4582e41f4b71Sopenharmony_ci            let context = getContext(this);
4583e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4584e41f4b71Sopenharmony_ci            gzflushDemo(pathDir);
4585e41f4b71Sopenharmony_ci          })
4586e41f4b71Sopenharmony_ci      }
4587e41f4b71Sopenharmony_ci      .width('100%')
4588e41f4b71Sopenharmony_ci    }
4589e41f4b71Sopenharmony_ci    .height('100%')
4590e41f4b71Sopenharmony_ci  }
4591e41f4b71Sopenharmony_ci}
4592e41f4b71Sopenharmony_ci```
4593e41f4b71Sopenharmony_ci
4594e41f4b71Sopenharmony_ci### gzfwrite<sup>12+</sup>
4595e41f4b71Sopenharmony_ci
4596e41f4b71Sopenharmony_cigzfwrite(buf: ArrayBuffer, size: number, nitems: number): Promise&lt;number&gt;
4597e41f4b71Sopenharmony_ci
4598e41f4b71Sopenharmony_ci将大小为size,数量为nitems的数据块从buf压缩并写入文件。
4599e41f4b71Sopenharmony_ci
4600e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4601e41f4b71Sopenharmony_ci
4602e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4603e41f4b71Sopenharmony_ci
4604e41f4b71Sopenharmony_ci**参数:**
4605e41f4b71Sopenharmony_ci
4606e41f4b71Sopenharmony_ci| 参数名 | 类型        | 必填 | 说明                   |
4607e41f4b71Sopenharmony_ci| ------ | ----------- | ---- | ---------------------- |
4608e41f4b71Sopenharmony_ci| buf    | ArrayBuffer | 是   | 要将数据写入的缓冲区。 |
4609e41f4b71Sopenharmony_ci| size   | number      | 是   | 单个数据块中的字节数。 |
4610e41f4b71Sopenharmony_ci| nitems | number      | 是   | 要写入的数据块数。     |
4611e41f4b71Sopenharmony_ci
4612e41f4b71Sopenharmony_ci**返回值:**
4613e41f4b71Sopenharmony_ci
4614e41f4b71Sopenharmony_ci| 类型                  | 说明                                                |
4615e41f4b71Sopenharmony_ci| --------------------- | --------------------------------------------------- |
4616e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回写入大小为size的完整数据块的数目。 |
4617e41f4b71Sopenharmony_ci
4618e41f4b71Sopenharmony_ci**错误码:**
4619e41f4b71Sopenharmony_ci
4620e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
4621e41f4b71Sopenharmony_ci
4622e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
4623e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
4624e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
4625e41f4b71Sopenharmony_ci| 17800009 | Internal structure error.                                    |
4626e41f4b71Sopenharmony_ci
4627e41f4b71Sopenharmony_ci**示例:**
4628e41f4b71Sopenharmony_ci
4629e41f4b71Sopenharmony_ci```ts
4630e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4631e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4632e41f4b71Sopenharmony_ci
4633e41f4b71Sopenharmony_ciasync function gzfwriteDemo(pathDir: string) {
4634e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzfwrite");
4635e41f4b71Sopenharmony_ci  let path = pathDir + "/gzfwrite/test.gz";
4636e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4637e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4638e41f4b71Sopenharmony_ci  let bufferWithData = new ArrayBuffer(16);
4639e41f4b71Sopenharmony_ci  let uint8View = new Uint8Array(bufferWithData);
4640e41f4b71Sopenharmony_ci  for (let i = 0; i < uint8View.length; i++) {
4641e41f4b71Sopenharmony_ci    uint8View[i] = i;
4642e41f4b71Sopenharmony_ci  }
4643e41f4b71Sopenharmony_ci  let resulit = await gzip.gzfwrite(bufferWithData, 8, 2)
4644e41f4b71Sopenharmony_ci  await gzip.gzclose();
4645e41f4b71Sopenharmony_ci}
4646e41f4b71Sopenharmony_ci
4647e41f4b71Sopenharmony_ci@Entry
4648e41f4b71Sopenharmony_ci@Component
4649e41f4b71Sopenharmony_cistruct Index {
4650e41f4b71Sopenharmony_ci  build() {
4651e41f4b71Sopenharmony_ci    Row() {
4652e41f4b71Sopenharmony_ci      Column() {
4653e41f4b71Sopenharmony_ci        Button('test gzip interface')
4654e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4655e41f4b71Sopenharmony_ci          .height(60)
4656e41f4b71Sopenharmony_ci          .width(200)
4657e41f4b71Sopenharmony_ci          .onClick(() => {
4658e41f4b71Sopenharmony_ci            let context = getContext(this);
4659e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4660e41f4b71Sopenharmony_ci            gzfwriteDemo(pathDir);
4661e41f4b71Sopenharmony_ci          })
4662e41f4b71Sopenharmony_ci      }
4663e41f4b71Sopenharmony_ci      .width('100%')
4664e41f4b71Sopenharmony_ci    }
4665e41f4b71Sopenharmony_ci    .height('100%')
4666e41f4b71Sopenharmony_ci  }
4667e41f4b71Sopenharmony_ci}
4668e41f4b71Sopenharmony_ci```
4669e41f4b71Sopenharmony_ci
4670e41f4b71Sopenharmony_ci### gzfread<sup>12+</sup>
4671e41f4b71Sopenharmony_ci
4672e41f4b71Sopenharmony_cigzfread(buf: ArrayBuffer, size: number, nitems: number): Promise&lt;number&gt;
4673e41f4b71Sopenharmony_ci
4674e41f4b71Sopenharmony_ci从gzip压缩文件中解压缩并读取数据。
4675e41f4b71Sopenharmony_ci
4676e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4677e41f4b71Sopenharmony_ci
4678e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4679e41f4b71Sopenharmony_ci
4680e41f4b71Sopenharmony_ci**参数:**
4681e41f4b71Sopenharmony_ci
4682e41f4b71Sopenharmony_ci| 参数名 | 类型        | 必填 | 说明                           |
4683e41f4b71Sopenharmony_ci| ------ | ----------- | ---- | ------------------------------ |
4684e41f4b71Sopenharmony_ci| buf    | ArrayBuffer | 是   | 用于存储读取结果的目标缓冲区。 |
4685e41f4b71Sopenharmony_ci| size   | number      | 是   | 单个数据块中的字节数。         |
4686e41f4b71Sopenharmony_ci| nitems | number      | 是   | 要写入的数据块数。             |
4687e41f4b71Sopenharmony_ci
4688e41f4b71Sopenharmony_ci**返回值:**
4689e41f4b71Sopenharmony_ci
4690e41f4b71Sopenharmony_ci| 类型                  | 说明                                                |
4691e41f4b71Sopenharmony_ci| --------------------- | --------------------------------------------------- |
4692e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回读取大小为size的完整数据块的数目。 |
4693e41f4b71Sopenharmony_ci
4694e41f4b71Sopenharmony_ci**错误码:**
4695e41f4b71Sopenharmony_ci
4696e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
4697e41f4b71Sopenharmony_ci
4698e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
4699e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
4700e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
4701e41f4b71Sopenharmony_ci| 17800009 | Internal structure error.                                    |
4702e41f4b71Sopenharmony_ci
4703e41f4b71Sopenharmony_ci**示例:**
4704e41f4b71Sopenharmony_ci
4705e41f4b71Sopenharmony_ci```ts
4706e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4707e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4708e41f4b71Sopenharmony_ci
4709e41f4b71Sopenharmony_ciasync function gzfreadDemo(pathDir: string) {
4710e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzfread");
4711e41f4b71Sopenharmony_ci  let path = pathDir + "/gzfread/test.gz";
4712e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4713e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4714e41f4b71Sopenharmony_ci  let writeBuffer = new ArrayBuffer(16);
4715e41f4b71Sopenharmony_ci  let uint8View = new Uint8Array(writeBuffer);
4716e41f4b71Sopenharmony_ci  for (let i = 0; i < uint8View.length; i++) {
4717e41f4b71Sopenharmony_ci    uint8View[i] = i;
4718e41f4b71Sopenharmony_ci  }
4719e41f4b71Sopenharmony_ci  await gzip.gzfwrite(writeBuffer, 8, 2);
4720e41f4b71Sopenharmony_ci  await gzip.gzclose();
4721e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "rb");
4722e41f4b71Sopenharmony_ci  let readBuffer = new ArrayBuffer(16);
4723e41f4b71Sopenharmony_ci  let result = await gzip.gzfread(readBuffer, 8, 2);
4724e41f4b71Sopenharmony_ci  await gzip.gzclose();
4725e41f4b71Sopenharmony_ci}
4726e41f4b71Sopenharmony_ci
4727e41f4b71Sopenharmony_ci@Entry
4728e41f4b71Sopenharmony_ci@Component
4729e41f4b71Sopenharmony_cistruct Index {
4730e41f4b71Sopenharmony_ci  build() {
4731e41f4b71Sopenharmony_ci    Row() {
4732e41f4b71Sopenharmony_ci      Column() {
4733e41f4b71Sopenharmony_ci        Button('test gzip interface')
4734e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4735e41f4b71Sopenharmony_ci          .height(60)
4736e41f4b71Sopenharmony_ci          .width(200)
4737e41f4b71Sopenharmony_ci          .onClick(() => {
4738e41f4b71Sopenharmony_ci            let context = getContext(this);
4739e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4740e41f4b71Sopenharmony_ci            gzfreadDemo(pathDir);
4741e41f4b71Sopenharmony_ci          })
4742e41f4b71Sopenharmony_ci      }
4743e41f4b71Sopenharmony_ci      .width('100%')
4744e41f4b71Sopenharmony_ci    }
4745e41f4b71Sopenharmony_ci    .height('100%')
4746e41f4b71Sopenharmony_ci  }
4747e41f4b71Sopenharmony_ci}
4748e41f4b71Sopenharmony_ci```
4749e41f4b71Sopenharmony_ci
4750e41f4b71Sopenharmony_ci### gzclosew<sup>12+</sup>
4751e41f4b71Sopenharmony_ci
4752e41f4b71Sopenharmony_cigzclosew(): Promise&lt;ReturnStatus&gt;
4753e41f4b71Sopenharmony_ci
4754e41f4b71Sopenharmony_ci与gzclose()功能相同,仅适用于写入或追加时。
4755e41f4b71Sopenharmony_ci
4756e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4757e41f4b71Sopenharmony_ci
4758e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4759e41f4b71Sopenharmony_ci
4760e41f4b71Sopenharmony_ci**返回值:**
4761e41f4b71Sopenharmony_ci
4762e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
4763e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
4764e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象,返回结果状态。 |
4765e41f4b71Sopenharmony_ci
4766e41f4b71Sopenharmony_ci**错误码:**
4767e41f4b71Sopenharmony_ci
4768e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.zlib错误码](./errorcode-zlib.md)。
4769e41f4b71Sopenharmony_ci
4770e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
4771e41f4b71Sopenharmony_ci| -------- | ------------------------- |
4772e41f4b71Sopenharmony_ci| 17800004 | ZStream error.            |
4773e41f4b71Sopenharmony_ci| 17800006 | Memory allocation failed. |
4774e41f4b71Sopenharmony_ci
4775e41f4b71Sopenharmony_ci**示例:**
4776e41f4b71Sopenharmony_ci
4777e41f4b71Sopenharmony_ci```ts
4778e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4779e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4780e41f4b71Sopenharmony_ci
4781e41f4b71Sopenharmony_ciasync function gzclosewDemo(pathDir: string) {
4782e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzclosew");
4783e41f4b71Sopenharmony_ci  let path = pathDir + "/gzclosew/test.gz";
4784e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4785e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4786e41f4b71Sopenharmony_ci  await gzip.gzclosew();
4787e41f4b71Sopenharmony_ci}
4788e41f4b71Sopenharmony_ci
4789e41f4b71Sopenharmony_ci@Entry
4790e41f4b71Sopenharmony_ci@Component
4791e41f4b71Sopenharmony_cistruct Index {
4792e41f4b71Sopenharmony_ci  build() {
4793e41f4b71Sopenharmony_ci    Row() {
4794e41f4b71Sopenharmony_ci      Column() {
4795e41f4b71Sopenharmony_ci        Button('test gzip interface')
4796e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4797e41f4b71Sopenharmony_ci          .height(60)
4798e41f4b71Sopenharmony_ci          .width(200)
4799e41f4b71Sopenharmony_ci          .onClick(() => {
4800e41f4b71Sopenharmony_ci            let context = getContext(this);
4801e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4802e41f4b71Sopenharmony_ci            gzclosewDemo(pathDir);
4803e41f4b71Sopenharmony_ci          })
4804e41f4b71Sopenharmony_ci      }
4805e41f4b71Sopenharmony_ci      .width('100%')
4806e41f4b71Sopenharmony_ci    }
4807e41f4b71Sopenharmony_ci    .height('100%')
4808e41f4b71Sopenharmony_ci  }
4809e41f4b71Sopenharmony_ci}
4810e41f4b71Sopenharmony_ci```
4811e41f4b71Sopenharmony_ci
4812e41f4b71Sopenharmony_ci### gzcloser<sup>12+</sup>
4813e41f4b71Sopenharmony_ci
4814e41f4b71Sopenharmony_cigzcloser(): Promise&lt;ReturnStatus&gt;
4815e41f4b71Sopenharmony_ci
4816e41f4b71Sopenharmony_ci与gzclose()功能相同,仅适用于读取时。
4817e41f4b71Sopenharmony_ci
4818e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4819e41f4b71Sopenharmony_ci
4820e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4821e41f4b71Sopenharmony_ci
4822e41f4b71Sopenharmony_ci**返回值:**
4823e41f4b71Sopenharmony_ci
4824e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
4825e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
4826e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象,返回结果状态。 |
4827e41f4b71Sopenharmony_ci
4828e41f4b71Sopenharmony_ci**错误码:**
4829e41f4b71Sopenharmony_ci
4830e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.zlib错误码](./errorcode-zlib.md)。
4831e41f4b71Sopenharmony_ci
4832e41f4b71Sopenharmony_ci| 错误码ID | 错误信息       |
4833e41f4b71Sopenharmony_ci| -------- | -------------- |
4834e41f4b71Sopenharmony_ci| 17800004 | ZStream error. |
4835e41f4b71Sopenharmony_ci
4836e41f4b71Sopenharmony_ci**示例:**
4837e41f4b71Sopenharmony_ci
4838e41f4b71Sopenharmony_ci```ts
4839e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4840e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4841e41f4b71Sopenharmony_ci
4842e41f4b71Sopenharmony_ciasync function gzcloserDemo(pathDir: string) {
4843e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzcloser");
4844e41f4b71Sopenharmony_ci  let path = pathDir + "/gzcloser/test.gz";
4845e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4846e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4847e41f4b71Sopenharmony_ci  await gzip.gzclose();
4848e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "rb");
4849e41f4b71Sopenharmony_ci  await gzip.gzcloser();
4850e41f4b71Sopenharmony_ci}
4851e41f4b71Sopenharmony_ci
4852e41f4b71Sopenharmony_ci@Entry
4853e41f4b71Sopenharmony_ci@Component
4854e41f4b71Sopenharmony_cistruct Index {
4855e41f4b71Sopenharmony_ci  build() {
4856e41f4b71Sopenharmony_ci    Row() {
4857e41f4b71Sopenharmony_ci      Column() {
4858e41f4b71Sopenharmony_ci        Button('test gzip interface')
4859e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4860e41f4b71Sopenharmony_ci          .height(60)
4861e41f4b71Sopenharmony_ci          .width(200)
4862e41f4b71Sopenharmony_ci          .onClick(() => {
4863e41f4b71Sopenharmony_ci            let context = getContext(this);
4864e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4865e41f4b71Sopenharmony_ci            gzcloserDemo(pathDir);
4866e41f4b71Sopenharmony_ci          })
4867e41f4b71Sopenharmony_ci      }
4868e41f4b71Sopenharmony_ci      .width('100%')
4869e41f4b71Sopenharmony_ci    }
4870e41f4b71Sopenharmony_ci    .height('100%')
4871e41f4b71Sopenharmony_ci  }
4872e41f4b71Sopenharmony_ci}
4873e41f4b71Sopenharmony_ci```
4874e41f4b71Sopenharmony_ci
4875e41f4b71Sopenharmony_ci### gzwrite<sup>12+</sup>
4876e41f4b71Sopenharmony_ci
4877e41f4b71Sopenharmony_cigzwrite(buf: ArrayBuffer, len: number): Promise&lt;number&gt;
4878e41f4b71Sopenharmony_ci
4879e41f4b71Sopenharmony_ci将buf中的len长度的未压缩字节进行压缩并将其写入文件。
4880e41f4b71Sopenharmony_ci
4881e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4882e41f4b71Sopenharmony_ci
4883e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4884e41f4b71Sopenharmony_ci
4885e41f4b71Sopenharmony_ci| 参数名 | 类型        | 必填 | 说明                         |
4886e41f4b71Sopenharmony_ci| ------ | ----------- | ---- | ---------------------------- |
4887e41f4b71Sopenharmony_ci| buf    | ArrayBuffer | 是   | 对象指向要写入的数据缓冲区。 |
4888e41f4b71Sopenharmony_ci| len    | number      | 是   | 未压缩字节长度。             |
4889e41f4b71Sopenharmony_ci
4890e41f4b71Sopenharmony_ci**返回值:**
4891e41f4b71Sopenharmony_ci
4892e41f4b71Sopenharmony_ci| 类型                  | 说明                                  |
4893e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------- |
4894e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回写入的未压缩字节数。 |
4895e41f4b71Sopenharmony_ci
4896e41f4b71Sopenharmony_ci**错误码:**
4897e41f4b71Sopenharmony_ci
4898e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
4899e41f4b71Sopenharmony_ci
4900e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
4901e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
4902e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
4903e41f4b71Sopenharmony_ci| 17800009 | Internal structure error.                                    |
4904e41f4b71Sopenharmony_ci
4905e41f4b71Sopenharmony_ci**示例:**
4906e41f4b71Sopenharmony_ci
4907e41f4b71Sopenharmony_ci```ts
4908e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4909e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4910e41f4b71Sopenharmony_ci
4911e41f4b71Sopenharmony_ciasync function gzwriteDemo(pathDir: string) {
4912e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzwrite");
4913e41f4b71Sopenharmony_ci  let path = pathDir + "/gzwrite/test.gz";
4914e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4915e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4916e41f4b71Sopenharmony_ci  let bufferWithData = new ArrayBuffer(16);
4917e41f4b71Sopenharmony_ci  let uint8View = new Uint8Array(bufferWithData);
4918e41f4b71Sopenharmony_ci  for (let i = 0; i < uint8View.length; i++) {
4919e41f4b71Sopenharmony_ci    uint8View[i] = i;
4920e41f4b71Sopenharmony_ci  }
4921e41f4b71Sopenharmony_ci  let result = await gzip.gzwrite(bufferWithData, 16);
4922e41f4b71Sopenharmony_ci  await gzip.gzclose();
4923e41f4b71Sopenharmony_ci}
4924e41f4b71Sopenharmony_ci
4925e41f4b71Sopenharmony_ci@Entry
4926e41f4b71Sopenharmony_ci@Component
4927e41f4b71Sopenharmony_cistruct Index {
4928e41f4b71Sopenharmony_ci  build() {
4929e41f4b71Sopenharmony_ci    Row() {
4930e41f4b71Sopenharmony_ci      Column() {
4931e41f4b71Sopenharmony_ci        Button('test gzip interface')
4932e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
4933e41f4b71Sopenharmony_ci          .height(60)
4934e41f4b71Sopenharmony_ci          .width(200)
4935e41f4b71Sopenharmony_ci          .onClick(() => {
4936e41f4b71Sopenharmony_ci            let context = getContext(this);
4937e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
4938e41f4b71Sopenharmony_ci            gzwriteDemo(pathDir);
4939e41f4b71Sopenharmony_ci          })
4940e41f4b71Sopenharmony_ci      }
4941e41f4b71Sopenharmony_ci      .width('100%')
4942e41f4b71Sopenharmony_ci    }
4943e41f4b71Sopenharmony_ci    .height('100%')
4944e41f4b71Sopenharmony_ci  }
4945e41f4b71Sopenharmony_ci}
4946e41f4b71Sopenharmony_ci```
4947e41f4b71Sopenharmony_ci
4948e41f4b71Sopenharmony_ci### gzungetc<sup>12+</sup>
4949e41f4b71Sopenharmony_ci
4950e41f4b71Sopenharmony_cigzungetc(c: number): Promise&lt;number&gt;
4951e41f4b71Sopenharmony_ci
4952e41f4b71Sopenharmony_ci将c推回到流中,以便在下次读取文件时将作为第一个字符读取。
4953e41f4b71Sopenharmony_ci
4954e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4955e41f4b71Sopenharmony_ci
4956e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
4957e41f4b71Sopenharmony_ci
4958e41f4b71Sopenharmony_ci| 参数名 | 类型   | 必填 | 说明                     |
4959e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------ |
4960e41f4b71Sopenharmony_ci| c      | number | 是   | 回退到输入流之前的字符。 |
4961e41f4b71Sopenharmony_ci
4962e41f4b71Sopenharmony_ci**返回值:**
4963e41f4b71Sopenharmony_ci
4964e41f4b71Sopenharmony_ci| 类型                  | 说明                          |
4965e41f4b71Sopenharmony_ci| --------------------- | ----------------------------- |
4966e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回推送的字符。 |
4967e41f4b71Sopenharmony_ci
4968e41f4b71Sopenharmony_ci**错误码:**
4969e41f4b71Sopenharmony_ci
4970e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
4971e41f4b71Sopenharmony_ci
4972e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
4973e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
4974e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
4975e41f4b71Sopenharmony_ci| 17800009 | Internal structure error.                                    |
4976e41f4b71Sopenharmony_ci
4977e41f4b71Sopenharmony_ci**示例:**
4978e41f4b71Sopenharmony_ci
4979e41f4b71Sopenharmony_ci```ts
4980e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
4981e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
4982e41f4b71Sopenharmony_ci
4983e41f4b71Sopenharmony_ciasync function gzungetcDemo(pathDir: string) {
4984e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzungetc");
4985e41f4b71Sopenharmony_ci  let path = pathDir + "/gzungetc/test.gz";
4986e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
4987e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
4988e41f4b71Sopenharmony_ci  await gzip.gzclose();
4989e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "rb");
4990e41f4b71Sopenharmony_ci  await gzip.gzread(new ArrayBuffer(1));
4991e41f4b71Sopenharmony_ci  let result = await gzip.gzungetc(1);
4992e41f4b71Sopenharmony_ci  await gzip.gzclose();
4993e41f4b71Sopenharmony_ci}
4994e41f4b71Sopenharmony_ci
4995e41f4b71Sopenharmony_ci@Entry
4996e41f4b71Sopenharmony_ci@Component
4997e41f4b71Sopenharmony_cistruct Index {
4998e41f4b71Sopenharmony_ci  build() {
4999e41f4b71Sopenharmony_ci    Row() {
5000e41f4b71Sopenharmony_ci      Column() {
5001e41f4b71Sopenharmony_ci        Button('test gzip interface')
5002e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
5003e41f4b71Sopenharmony_ci          .height(60)
5004e41f4b71Sopenharmony_ci          .width(200)
5005e41f4b71Sopenharmony_ci          .onClick(() => {
5006e41f4b71Sopenharmony_ci            let context = getContext(this);
5007e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
5008e41f4b71Sopenharmony_ci            gzungetcDemo(pathDir);
5009e41f4b71Sopenharmony_ci          })
5010e41f4b71Sopenharmony_ci      }
5011e41f4b71Sopenharmony_ci      .width('100%')
5012e41f4b71Sopenharmony_ci    }
5013e41f4b71Sopenharmony_ci    .height('100%')
5014e41f4b71Sopenharmony_ci  }
5015e41f4b71Sopenharmony_ci}
5016e41f4b71Sopenharmony_ci```
5017e41f4b71Sopenharmony_ci
5018e41f4b71Sopenharmony_ci### gztell<sup>12+</sup>
5019e41f4b71Sopenharmony_ci
5020e41f4b71Sopenharmony_cigztell(): Promise&lt;number&gt;
5021e41f4b71Sopenharmony_ci
5022e41f4b71Sopenharmony_ci返回文件中下一个gzread或gzwrite的起始位置。
5023e41f4b71Sopenharmony_ci
5024e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5025e41f4b71Sopenharmony_ci
5026e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
5027e41f4b71Sopenharmony_ci
5028e41f4b71Sopenharmony_ci**返回值:**
5029e41f4b71Sopenharmony_ci
5030e41f4b71Sopenharmony_ci| 类型                  | 说明                                                     |
5031e41f4b71Sopenharmony_ci| --------------------- | -------------------------------------------------------- |
5032e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回文件种下一个gzread或gzwrite的起始位置。 |
5033e41f4b71Sopenharmony_ci
5034e41f4b71Sopenharmony_ci**错误码:**
5035e41f4b71Sopenharmony_ci
5036e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.zlib错误码](./errorcode-zlib.md)。
5037e41f4b71Sopenharmony_ci
5038e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
5039e41f4b71Sopenharmony_ci| -------- | ------------------------- |
5040e41f4b71Sopenharmony_ci| 17800009 | Internal structure error. |
5041e41f4b71Sopenharmony_ci
5042e41f4b71Sopenharmony_ci**示例:**
5043e41f4b71Sopenharmony_ci
5044e41f4b71Sopenharmony_ci```ts
5045e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
5046e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
5047e41f4b71Sopenharmony_ci
5048e41f4b71Sopenharmony_ciasync function gztellDemo(pathDir: string) {
5049e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gztell");
5050e41f4b71Sopenharmony_ci  let path = pathDir + "/gztell/test.gz";
5051e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
5052e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
5053e41f4b71Sopenharmony_ci  let result = await gzip.gztell();
5054e41f4b71Sopenharmony_ci  await gzip.gzclose();
5055e41f4b71Sopenharmony_ci}
5056e41f4b71Sopenharmony_ci
5057e41f4b71Sopenharmony_ci@Entry
5058e41f4b71Sopenharmony_ci@Component
5059e41f4b71Sopenharmony_cistruct Index {
5060e41f4b71Sopenharmony_ci  build() {
5061e41f4b71Sopenharmony_ci    Row() {
5062e41f4b71Sopenharmony_ci      Column() {
5063e41f4b71Sopenharmony_ci        Button('test gzip interface')
5064e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
5065e41f4b71Sopenharmony_ci          .height(60)
5066e41f4b71Sopenharmony_ci          .width(200)
5067e41f4b71Sopenharmony_ci          .onClick(() => {
5068e41f4b71Sopenharmony_ci            let context = getContext(this);
5069e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
5070e41f4b71Sopenharmony_ci            gztellDemo(pathDir);
5071e41f4b71Sopenharmony_ci          })
5072e41f4b71Sopenharmony_ci      }
5073e41f4b71Sopenharmony_ci      .width('100%')
5074e41f4b71Sopenharmony_ci    }
5075e41f4b71Sopenharmony_ci    .height('100%')
5076e41f4b71Sopenharmony_ci  }
5077e41f4b71Sopenharmony_ci}
5078e41f4b71Sopenharmony_ci```
5079e41f4b71Sopenharmony_ci
5080e41f4b71Sopenharmony_ci### gzsetparams<sup>12+</sup>
5081e41f4b71Sopenharmony_ci
5082e41f4b71Sopenharmony_cigzsetparams(level: CompressLevel, strategy: CompressStrategy): Promise&lt;ReturnStatus&gt;
5083e41f4b71Sopenharmony_ci
5084e41f4b71Sopenharmony_ci动态更新文件的压缩级别和压缩策略。
5085e41f4b71Sopenharmony_ci
5086e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5087e41f4b71Sopenharmony_ci
5088e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
5089e41f4b71Sopenharmony_ci
5090e41f4b71Sopenharmony_ci**参数:**
5091e41f4b71Sopenharmony_ci
5092e41f4b71Sopenharmony_ci| 参数名   | 类型             | 必填 | 说明                                                         |
5093e41f4b71Sopenharmony_ci| -------- | ---------------- | ---- | ------------------------------------------------------------ |
5094e41f4b71Sopenharmony_ci| level    | CompressLevel    | 是   | 压缩级别,参考[zip.CompressLevel枚举定义](#zipcompresslevel)。 |
5095e41f4b71Sopenharmony_ci| strategy | CompressStrategy | 是   | 压缩策略,参考[zip.CompressStrategy枚举定义](#zipcompressstrategy)。 |
5096e41f4b71Sopenharmony_ci
5097e41f4b71Sopenharmony_ci**返回值:**
5098e41f4b71Sopenharmony_ci
5099e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
5100e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
5101e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象,返回结果状态。 |
5102e41f4b71Sopenharmony_ci
5103e41f4b71Sopenharmony_ci**错误码:**
5104e41f4b71Sopenharmony_ci
5105e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
5106e41f4b71Sopenharmony_ci
5107e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
5108e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
5109e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
5110e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
5111e41f4b71Sopenharmony_ci
5112e41f4b71Sopenharmony_ci**示例:**
5113e41f4b71Sopenharmony_ci
5114e41f4b71Sopenharmony_ci```ts
5115e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
5116e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
5117e41f4b71Sopenharmony_ci
5118e41f4b71Sopenharmony_ciasync function gzsetparamsDemo(pathDir: string) {
5119e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzsetparams");
5120e41f4b71Sopenharmony_ci  let path = pathDir + "/gzsetparams/test.gz";
5121e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
5122e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
5123e41f4b71Sopenharmony_ci  let result = await gzip.gzsetparams(zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
5124e41f4b71Sopenharmony_ci    zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY);
5125e41f4b71Sopenharmony_ci  await gzip.gzclose();
5126e41f4b71Sopenharmony_ci}
5127e41f4b71Sopenharmony_ci
5128e41f4b71Sopenharmony_ci@Entry
5129e41f4b71Sopenharmony_ci@Component
5130e41f4b71Sopenharmony_cistruct Index {
5131e41f4b71Sopenharmony_ci  build() {
5132e41f4b71Sopenharmony_ci    Row() {
5133e41f4b71Sopenharmony_ci      Column() {
5134e41f4b71Sopenharmony_ci        Button('test gzip interface')
5135e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
5136e41f4b71Sopenharmony_ci          .height(60)
5137e41f4b71Sopenharmony_ci          .width(200)
5138e41f4b71Sopenharmony_ci          .onClick(() => {
5139e41f4b71Sopenharmony_ci            let context = getContext(this);
5140e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
5141e41f4b71Sopenharmony_ci            gzsetparamsDemo(pathDir);
5142e41f4b71Sopenharmony_ci          })
5143e41f4b71Sopenharmony_ci      }
5144e41f4b71Sopenharmony_ci      .width('100%')
5145e41f4b71Sopenharmony_ci    }
5146e41f4b71Sopenharmony_ci    .height('100%')
5147e41f4b71Sopenharmony_ci  }
5148e41f4b71Sopenharmony_ci}
5149e41f4b71Sopenharmony_ci```
5150e41f4b71Sopenharmony_ci
5151e41f4b71Sopenharmony_ci### gzseek<sup>12+</sup>
5152e41f4b71Sopenharmony_ci
5153e41f4b71Sopenharmony_cigzseek(offset: number, whence: OffsetReferencePoint): Promise&lt;number&gt;
5154e41f4b71Sopenharmony_ci
5155e41f4b71Sopenharmony_ci将起始位置设置为相对于文件中下一个gzread或gzwrite的偏移位置。
5156e41f4b71Sopenharmony_ci
5157e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5158e41f4b71Sopenharmony_ci
5159e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
5160e41f4b71Sopenharmony_ci
5161e41f4b71Sopenharmony_ci**参数:**
5162e41f4b71Sopenharmony_ci
5163e41f4b71Sopenharmony_ci| 参数名 | 类型                 | 必填 | 说明                                                         |
5164e41f4b71Sopenharmony_ci| ------ | -------------------- | ---- | ------------------------------------------------------------ |
5165e41f4b71Sopenharmony_ci| offset | number               | 是   | 目标偏移位置。                                               |
5166e41f4b71Sopenharmony_ci| whence | OffsetReferencePoint | 是   | 定义偏移的参考点,参考[zip.OffsetReferencePoint枚举定义](#zipoffsetreferencepoint12)。 |
5167e41f4b71Sopenharmony_ci
5168e41f4b71Sopenharmony_ci**返回值:**
5169e41f4b71Sopenharmony_ci
5170e41f4b71Sopenharmony_ci| 类型                  | 说明                                                         |
5171e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------------------------------ |
5172e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回从未压缩流开始以字节为单位测量的结果偏移位置。 |
5173e41f4b71Sopenharmony_ci
5174e41f4b71Sopenharmony_ci**错误码:**
5175e41f4b71Sopenharmony_ci
5176e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
5177e41f4b71Sopenharmony_ci
5178e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
5179e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
5180e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
5181e41f4b71Sopenharmony_ci| 17800009 | Internal structure error.                                    |
5182e41f4b71Sopenharmony_ci
5183e41f4b71Sopenharmony_ci**示例:**
5184e41f4b71Sopenharmony_ci
5185e41f4b71Sopenharmony_ci```ts
5186e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
5187e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
5188e41f4b71Sopenharmony_ci
5189e41f4b71Sopenharmony_ciasync function gzseekDemo(pathDir: string) {
5190e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzseek");
5191e41f4b71Sopenharmony_ci  let path = pathDir + "/gzseek/test.gz";
5192e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
5193e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
5194e41f4b71Sopenharmony_ci  let result = await gzip.gzseek(2, zlib.OffsetReferencePoint.SEEK_CUR);
5195e41f4b71Sopenharmony_ci  await gzip.gzclose();
5196e41f4b71Sopenharmony_ci}
5197e41f4b71Sopenharmony_ci
5198e41f4b71Sopenharmony_ci@Entry
5199e41f4b71Sopenharmony_ci@Component
5200e41f4b71Sopenharmony_cistruct Index {
5201e41f4b71Sopenharmony_ci  build() {
5202e41f4b71Sopenharmony_ci    Row() {
5203e41f4b71Sopenharmony_ci      Column() {
5204e41f4b71Sopenharmony_ci        Button('test gzip interface')
5205e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
5206e41f4b71Sopenharmony_ci          .height(60)
5207e41f4b71Sopenharmony_ci          .width(200)
5208e41f4b71Sopenharmony_ci          .onClick(() => {
5209e41f4b71Sopenharmony_ci            let context = getContext(this);
5210e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
5211e41f4b71Sopenharmony_ci            gzseekDemo(pathDir);
5212e41f4b71Sopenharmony_ci          })
5213e41f4b71Sopenharmony_ci      }
5214e41f4b71Sopenharmony_ci      .width('100%')
5215e41f4b71Sopenharmony_ci    }
5216e41f4b71Sopenharmony_ci    .height('100%')
5217e41f4b71Sopenharmony_ci  }
5218e41f4b71Sopenharmony_ci}
5219e41f4b71Sopenharmony_ci```
5220e41f4b71Sopenharmony_ci
5221e41f4b71Sopenharmony_ci### gzrewind<sup>12+</sup>
5222e41f4b71Sopenharmony_ci
5223e41f4b71Sopenharmony_cigzrewind(): Promise&lt;ReturnStatus&gt;
5224e41f4b71Sopenharmony_ci
5225e41f4b71Sopenharmony_ci将文件指针重新定位到文件的开头,此功能仅用于读取。
5226e41f4b71Sopenharmony_ci
5227e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5228e41f4b71Sopenharmony_ci
5229e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
5230e41f4b71Sopenharmony_ci
5231e41f4b71Sopenharmony_ci**返回值:**
5232e41f4b71Sopenharmony_ci
5233e41f4b71Sopenharmony_ci| 类型                                              | 说明                        |
5234e41f4b71Sopenharmony_ci| ------------------------------------------------- | --------------------------- |
5235e41f4b71Sopenharmony_ci| Promise&lt;[ReturnStatus](#zipreturnstatus12)&gt; | Promise对象,返回结果状态。 |
5236e41f4b71Sopenharmony_ci
5237e41f4b71Sopenharmony_ci**错误码:**
5238e41f4b71Sopenharmony_ci
5239e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.zlib错误码](./errorcode-zlib.md)。
5240e41f4b71Sopenharmony_ci
5241e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
5242e41f4b71Sopenharmony_ci| -------- | ------------------------- |
5243e41f4b71Sopenharmony_ci| 17800009 | Internal structure error. |
5244e41f4b71Sopenharmony_ci
5245e41f4b71Sopenharmony_ci**示例:**
5246e41f4b71Sopenharmony_ci
5247e41f4b71Sopenharmony_ci```ts
5248e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
5249e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
5250e41f4b71Sopenharmony_ci
5251e41f4b71Sopenharmony_ciasync function gzrewindDemo(pathDir: string) {
5252e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzrewind");
5253e41f4b71Sopenharmony_ci  let path = pathDir + "/gzrewind/test.gz";
5254e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
5255e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
5256e41f4b71Sopenharmony_ci  await gzip.gzclose();
5257e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "rb");
5258e41f4b71Sopenharmony_ci  let result = await gzip.gzrewind();
5259e41f4b71Sopenharmony_ci  await gzip.gzclose();
5260e41f4b71Sopenharmony_ci}
5261e41f4b71Sopenharmony_ci
5262e41f4b71Sopenharmony_ci@Entry
5263e41f4b71Sopenharmony_ci@Component
5264e41f4b71Sopenharmony_cistruct Index {
5265e41f4b71Sopenharmony_ci  build() {
5266e41f4b71Sopenharmony_ci    Row() {
5267e41f4b71Sopenharmony_ci      Column() {
5268e41f4b71Sopenharmony_ci        Button('test gzip interface')
5269e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
5270e41f4b71Sopenharmony_ci          .height(60)
5271e41f4b71Sopenharmony_ci          .width(200)
5272e41f4b71Sopenharmony_ci          .onClick(() => {
5273e41f4b71Sopenharmony_ci            let context = getContext(this);
5274e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
5275e41f4b71Sopenharmony_ci            gzrewindDemo(pathDir);
5276e41f4b71Sopenharmony_ci          })
5277e41f4b71Sopenharmony_ci      }
5278e41f4b71Sopenharmony_ci      .width('100%')
5279e41f4b71Sopenharmony_ci    }
5280e41f4b71Sopenharmony_ci    .height('100%')
5281e41f4b71Sopenharmony_ci  }
5282e41f4b71Sopenharmony_ci}
5283e41f4b71Sopenharmony_ci```
5284e41f4b71Sopenharmony_ci
5285e41f4b71Sopenharmony_ci### gzread<sup>12+</sup>
5286e41f4b71Sopenharmony_ci
5287e41f4b71Sopenharmony_cigzread(buf: ArrayBuffer): Promise&lt;number&gt;
5288e41f4b71Sopenharmony_ci
5289e41f4b71Sopenharmony_ci从文件中读取最多len个未压缩字节并将其解压缩到buf中。
5290e41f4b71Sopenharmony_ci
5291e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5292e41f4b71Sopenharmony_ci
5293e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
5294e41f4b71Sopenharmony_ci
5295e41f4b71Sopenharmony_ci**参数:**
5296e41f4b71Sopenharmony_ci
5297e41f4b71Sopenharmony_ci| 参数名 | 类型        | 必填 | 说明           |
5298e41f4b71Sopenharmony_ci| ------ | ----------- | ---- | -------------- |
5299e41f4b71Sopenharmony_ci| buf    | ArrayBuffer | 是   | 目标偏移位置。 |
5300e41f4b71Sopenharmony_ci
5301e41f4b71Sopenharmony_ci**返回值:**
5302e41f4b71Sopenharmony_ci
5303e41f4b71Sopenharmony_ci| 类型                  | 说明                                      |
5304e41f4b71Sopenharmony_ci| --------------------- | ----------------------------------------- |
5305e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回实际读取的未压缩字节数。 |
5306e41f4b71Sopenharmony_ci
5307e41f4b71Sopenharmony_ci**错误码:**
5308e41f4b71Sopenharmony_ci
5309e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
5310e41f4b71Sopenharmony_ci
5311e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
5312e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
5313e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
5314e41f4b71Sopenharmony_ci| 17800009 | Internal structure error.                                    |
5315e41f4b71Sopenharmony_ci
5316e41f4b71Sopenharmony_ci**示例:**
5317e41f4b71Sopenharmony_ci
5318e41f4b71Sopenharmony_ci```ts
5319e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
5320e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
5321e41f4b71Sopenharmony_ci
5322e41f4b71Sopenharmony_ciasync function gzreadDemo(pathDir: string) {
5323e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzread");
5324e41f4b71Sopenharmony_ci  let path = pathDir + "/gzread/test.gz";
5325e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
5326e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
5327e41f4b71Sopenharmony_ci  let writeBuffer = new ArrayBuffer(16);
5328e41f4b71Sopenharmony_ci  let uint8View = new Uint8Array(writeBuffer);
5329e41f4b71Sopenharmony_ci  for (let i = 0; i < uint8View.length; i++) {
5330e41f4b71Sopenharmony_ci    uint8View[i] = i;
5331e41f4b71Sopenharmony_ci  }
5332e41f4b71Sopenharmony_ci  await gzip.gzwrite(writeBuffer, 16);
5333e41f4b71Sopenharmony_ci  await gzip.gzclose();
5334e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "rb");
5335e41f4b71Sopenharmony_ci  let readBuffer = new ArrayBuffer(16);
5336e41f4b71Sopenharmony_ci  let result = await gzip.gzread(readBuffer);
5337e41f4b71Sopenharmony_ci  await gzip.gzclose();
5338e41f4b71Sopenharmony_ci}
5339e41f4b71Sopenharmony_ci
5340e41f4b71Sopenharmony_ci@Entry
5341e41f4b71Sopenharmony_ci@Component
5342e41f4b71Sopenharmony_cistruct Index {
5343e41f4b71Sopenharmony_ci  build() {
5344e41f4b71Sopenharmony_ci    Row() {
5345e41f4b71Sopenharmony_ci      Column() {
5346e41f4b71Sopenharmony_ci        Button('test gzip interface')
5347e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
5348e41f4b71Sopenharmony_ci          .height(60)
5349e41f4b71Sopenharmony_ci          .width(200)
5350e41f4b71Sopenharmony_ci          .onClick(() => {
5351e41f4b71Sopenharmony_ci            let context = getContext(this);
5352e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
5353e41f4b71Sopenharmony_ci            gzreadDemo(pathDir);
5354e41f4b71Sopenharmony_ci          })
5355e41f4b71Sopenharmony_ci      }
5356e41f4b71Sopenharmony_ci      .width('100%')
5357e41f4b71Sopenharmony_ci    }
5358e41f4b71Sopenharmony_ci    .height('100%')
5359e41f4b71Sopenharmony_ci  }
5360e41f4b71Sopenharmony_ci}
5361e41f4b71Sopenharmony_ci```
5362e41f4b71Sopenharmony_ci
5363e41f4b71Sopenharmony_ci### gzputs<sup>12+</sup>
5364e41f4b71Sopenharmony_ci
5365e41f4b71Sopenharmony_cigzputs(str: string): Promise&lt;number&gt;
5366e41f4b71Sopenharmony_ci
5367e41f4b71Sopenharmony_ci压缩给定的以null结尾的字符串并将其写入文件,不包括终止的null字符。
5368e41f4b71Sopenharmony_ci
5369e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5370e41f4b71Sopenharmony_ci
5371e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
5372e41f4b71Sopenharmony_ci
5373e41f4b71Sopenharmony_ci**参数:**
5374e41f4b71Sopenharmony_ci
5375e41f4b71Sopenharmony_ci| 参数名 | 类型   | 必填 | 说明                   |
5376e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------------- |
5377e41f4b71Sopenharmony_ci| str    | string | 是   | 格式化描述符和纯文本。 |
5378e41f4b71Sopenharmony_ci
5379e41f4b71Sopenharmony_ci**返回值:**
5380e41f4b71Sopenharmony_ci
5381e41f4b71Sopenharmony_ci| 类型                  | 说明                            |
5382e41f4b71Sopenharmony_ci| --------------------- | ------------------------------- |
5383e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回写入的字符数。 |
5384e41f4b71Sopenharmony_ci
5385e41f4b71Sopenharmony_ci**错误码:**
5386e41f4b71Sopenharmony_ci
5387e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
5388e41f4b71Sopenharmony_ci
5389e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
5390e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
5391e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
5392e41f4b71Sopenharmony_ci| 17800009 | Internal structure error.                                    |
5393e41f4b71Sopenharmony_ci
5394e41f4b71Sopenharmony_ci**示例:**
5395e41f4b71Sopenharmony_ci
5396e41f4b71Sopenharmony_ci```ts
5397e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
5398e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
5399e41f4b71Sopenharmony_ci
5400e41f4b71Sopenharmony_ciasync function gzputsDemo(pathDir: string) {
5401e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzputs");
5402e41f4b71Sopenharmony_ci  let path = pathDir + "/gzputs/test.gz";
5403e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
5404e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
5405e41f4b71Sopenharmony_ci  let result = await gzip.gzputs("hello");
5406e41f4b71Sopenharmony_ci  await gzip.gzclose();
5407e41f4b71Sopenharmony_ci}
5408e41f4b71Sopenharmony_ci
5409e41f4b71Sopenharmony_ci@Entry
5410e41f4b71Sopenharmony_ci@Component
5411e41f4b71Sopenharmony_cistruct Index {
5412e41f4b71Sopenharmony_ci  build() {
5413e41f4b71Sopenharmony_ci    Row() {
5414e41f4b71Sopenharmony_ci      Column() {
5415e41f4b71Sopenharmony_ci        Button('test gzip interface')
5416e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
5417e41f4b71Sopenharmony_ci          .height(60)
5418e41f4b71Sopenharmony_ci          .width(200)
5419e41f4b71Sopenharmony_ci          .onClick(() => {
5420e41f4b71Sopenharmony_ci            let context = getContext(this);
5421e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
5422e41f4b71Sopenharmony_ci            gzputsDemo(pathDir);
5423e41f4b71Sopenharmony_ci          })
5424e41f4b71Sopenharmony_ci      }
5425e41f4b71Sopenharmony_ci      .width('100%')
5426e41f4b71Sopenharmony_ci    }
5427e41f4b71Sopenharmony_ci    .height('100%')
5428e41f4b71Sopenharmony_ci  }
5429e41f4b71Sopenharmony_ci}
5430e41f4b71Sopenharmony_ci```
5431e41f4b71Sopenharmony_ci
5432e41f4b71Sopenharmony_ci### gzputc<sup>12+</sup>
5433e41f4b71Sopenharmony_ci
5434e41f4b71Sopenharmony_cigzputc(char: number): Promise&lt;number&gt;
5435e41f4b71Sopenharmony_ci
5436e41f4b71Sopenharmony_ci将转换为无符号字符的c压缩并写入文件。
5437e41f4b71Sopenharmony_ci
5438e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5439e41f4b71Sopenharmony_ci
5440e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
5441e41f4b71Sopenharmony_ci
5442e41f4b71Sopenharmony_ci**参数:**
5443e41f4b71Sopenharmony_ci
5444e41f4b71Sopenharmony_ci| 参数名 | 类型   | 必填 | 说明            |
5445e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------- |
5446e41f4b71Sopenharmony_ci| char   | number | 是   | 写入字符ASCII。 |
5447e41f4b71Sopenharmony_ci
5448e41f4b71Sopenharmony_ci**返回值:**
5449e41f4b71Sopenharmony_ci
5450e41f4b71Sopenharmony_ci| 类型                  | 说明                          |
5451e41f4b71Sopenharmony_ci| --------------------- | ----------------------------- |
5452e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回已写入的值。 |
5453e41f4b71Sopenharmony_ci
5454e41f4b71Sopenharmony_ci**错误码:**
5455e41f4b71Sopenharmony_ci
5456e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
5457e41f4b71Sopenharmony_ci
5458e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
5459e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
5460e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
5461e41f4b71Sopenharmony_ci| 17800009 | Internal structure error.                                    |
5462e41f4b71Sopenharmony_ci
5463e41f4b71Sopenharmony_ci**示例:**
5464e41f4b71Sopenharmony_ci
5465e41f4b71Sopenharmony_ci```ts
5466e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
5467e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
5468e41f4b71Sopenharmony_ci
5469e41f4b71Sopenharmony_ciasync function gzputcDemo(pathDir: string) {
5470e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzputc");
5471e41f4b71Sopenharmony_ci  let path = pathDir + "/gzputc/test.gz";
5472e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
5473e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
5474e41f4b71Sopenharmony_ci  let result = await gzip.gzputc(0);
5475e41f4b71Sopenharmony_ci  await gzip.gzclose();
5476e41f4b71Sopenharmony_ci}
5477e41f4b71Sopenharmony_ci
5478e41f4b71Sopenharmony_ci@Entry
5479e41f4b71Sopenharmony_ci@Component
5480e41f4b71Sopenharmony_cistruct Index {
5481e41f4b71Sopenharmony_ci  build() {
5482e41f4b71Sopenharmony_ci    Row() {
5483e41f4b71Sopenharmony_ci      Column() {
5484e41f4b71Sopenharmony_ci        Button('test gzip interface')
5485e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
5486e41f4b71Sopenharmony_ci          .height(60)
5487e41f4b71Sopenharmony_ci          .width(200)
5488e41f4b71Sopenharmony_ci          .onClick(() => {
5489e41f4b71Sopenharmony_ci            let context = getContext(this);
5490e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
5491e41f4b71Sopenharmony_ci            gzputcDemo(pathDir);
5492e41f4b71Sopenharmony_ci          })
5493e41f4b71Sopenharmony_ci      }
5494e41f4b71Sopenharmony_ci      .width('100%')
5495e41f4b71Sopenharmony_ci    }
5496e41f4b71Sopenharmony_ci    .height('100%')
5497e41f4b71Sopenharmony_ci  }
5498e41f4b71Sopenharmony_ci}
5499e41f4b71Sopenharmony_ci```
5500e41f4b71Sopenharmony_ci
5501e41f4b71Sopenharmony_ci### gzprintf<sup>12+</sup>
5502e41f4b71Sopenharmony_ci
5503e41f4b71Sopenharmony_cigzprintf(format: string, ...args: Array&lt;string | number&gt;): Promise&lt;number&gt;
5504e41f4b71Sopenharmony_ci
5505e41f4b71Sopenharmony_ci在字符串格式的控制下,将参数转换和格式化后,压缩并写入文件,如fprintf中所示。
5506e41f4b71Sopenharmony_ci
5507e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5508e41f4b71Sopenharmony_ci
5509e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
5510e41f4b71Sopenharmony_ci
5511e41f4b71Sopenharmony_ci**参数:**
5512e41f4b71Sopenharmony_ci
5513e41f4b71Sopenharmony_ci| 参数名 | 类型                          | 必填 | 说明                   |
5514e41f4b71Sopenharmony_ci| ------ | ----------------------------- | ---- | ---------------------- |
5515e41f4b71Sopenharmony_ci| format | string                        | 是   | 格式化描述符和纯文本。 |
5516e41f4b71Sopenharmony_ci| args   | Array&lt;string \| number&gt; | 否   | 可变参数列表。         |
5517e41f4b71Sopenharmony_ci
5518e41f4b71Sopenharmony_ci**返回值:**
5519e41f4b71Sopenharmony_ci
5520e41f4b71Sopenharmony_ci| 类型                  | 说明                                      |
5521e41f4b71Sopenharmony_ci| --------------------- | ----------------------------------------- |
5522e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回实际写入的未压缩字节数。 |
5523e41f4b71Sopenharmony_ci
5524e41f4b71Sopenharmony_ci**错误码:**
5525e41f4b71Sopenharmony_ci
5526e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
5527e41f4b71Sopenharmony_ci
5528e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
5529e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
5530e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
5531e41f4b71Sopenharmony_ci| 17800004 | ZStream error.                                               |
5532e41f4b71Sopenharmony_ci| 17800009 | Internal structure error.                                    |
5533e41f4b71Sopenharmony_ci
5534e41f4b71Sopenharmony_ci**示例:**
5535e41f4b71Sopenharmony_ci
5536e41f4b71Sopenharmony_ci```ts
5537e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
5538e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
5539e41f4b71Sopenharmony_ci
5540e41f4b71Sopenharmony_ciasync function gzprintfDemo(pathDir: string) {
5541e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzprintf");
5542e41f4b71Sopenharmony_ci  let path = pathDir + "/gzprintf/test.gz";
5543e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
5544e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
5545e41f4b71Sopenharmony_ci  let result = await gzip.gzprintf("name is %s, age is %d", "Tom", 23);
5546e41f4b71Sopenharmony_ci  await gzip.gzclose();
5547e41f4b71Sopenharmony_ci}
5548e41f4b71Sopenharmony_ci
5549e41f4b71Sopenharmony_ci@Entry
5550e41f4b71Sopenharmony_ci@Component
5551e41f4b71Sopenharmony_cistruct Index {
5552e41f4b71Sopenharmony_ci  build() {
5553e41f4b71Sopenharmony_ci    Row() {
5554e41f4b71Sopenharmony_ci      Column() {
5555e41f4b71Sopenharmony_ci        Button('test gzip interface')
5556e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
5557e41f4b71Sopenharmony_ci          .height(60)
5558e41f4b71Sopenharmony_ci          .width(200)
5559e41f4b71Sopenharmony_ci          .onClick(() => {
5560e41f4b71Sopenharmony_ci            let context = getContext(this);
5561e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
5562e41f4b71Sopenharmony_ci            gzprintfDemo(pathDir);
5563e41f4b71Sopenharmony_ci          })
5564e41f4b71Sopenharmony_ci      }
5565e41f4b71Sopenharmony_ci      .width('100%')
5566e41f4b71Sopenharmony_ci    }
5567e41f4b71Sopenharmony_ci    .height('100%')
5568e41f4b71Sopenharmony_ci  }
5569e41f4b71Sopenharmony_ci}
5570e41f4b71Sopenharmony_ci```
5571e41f4b71Sopenharmony_ci
5572e41f4b71Sopenharmony_ci### gzoffset<sup>12+</sup>
5573e41f4b71Sopenharmony_ci
5574e41f4b71Sopenharmony_cigzoffset(): Promise&lt;number&gt;
5575e41f4b71Sopenharmony_ci
5576e41f4b71Sopenharmony_ci返回文件的当前压缩(实际)读或写偏移量。
5577e41f4b71Sopenharmony_ci
5578e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5579e41f4b71Sopenharmony_ci
5580e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
5581e41f4b71Sopenharmony_ci
5582e41f4b71Sopenharmony_ci**返回值:**
5583e41f4b71Sopenharmony_ci
5584e41f4b71Sopenharmony_ci| 类型                  | 说明                                                  |
5585e41f4b71Sopenharmony_ci| --------------------- | ----------------------------------------------------- |
5586e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise对象,返回文件的当前压缩(实际)读或写偏移量。 |
5587e41f4b71Sopenharmony_ci
5588e41f4b71Sopenharmony_ci**错误码:**
5589e41f4b71Sopenharmony_ci
5590e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.zlib错误码](./errorcode-zlib.md)。
5591e41f4b71Sopenharmony_ci
5592e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
5593e41f4b71Sopenharmony_ci| -------- | ------------------------- |
5594e41f4b71Sopenharmony_ci| 17800009 | Internal structure error. |
5595e41f4b71Sopenharmony_ci
5596e41f4b71Sopenharmony_ci**示例:**
5597e41f4b71Sopenharmony_ci
5598e41f4b71Sopenharmony_ci```ts
5599e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
5600e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
5601e41f4b71Sopenharmony_ci
5602e41f4b71Sopenharmony_ciasync function gzoffsetDemo(pathDir: string) {
5603e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzoffset");
5604e41f4b71Sopenharmony_ci  let path = pathDir + "/gzoffset/test.gz";
5605e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
5606e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
5607e41f4b71Sopenharmony_ci  let result = await gzip.gzoffset();
5608e41f4b71Sopenharmony_ci  await gzip.gzclose();
5609e41f4b71Sopenharmony_ci}
5610e41f4b71Sopenharmony_ci
5611e41f4b71Sopenharmony_ci@Entry
5612e41f4b71Sopenharmony_ci@Component
5613e41f4b71Sopenharmony_cistruct Index {
5614e41f4b71Sopenharmony_ci  build() {
5615e41f4b71Sopenharmony_ci    Row() {
5616e41f4b71Sopenharmony_ci      Column() {
5617e41f4b71Sopenharmony_ci        Button('test gzip interface')
5618e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
5619e41f4b71Sopenharmony_ci          .height(60)
5620e41f4b71Sopenharmony_ci          .width(200)
5621e41f4b71Sopenharmony_ci          .onClick(() => {
5622e41f4b71Sopenharmony_ci            let context = getContext(this);
5623e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
5624e41f4b71Sopenharmony_ci            gzoffsetDemo(pathDir);
5625e41f4b71Sopenharmony_ci          })
5626e41f4b71Sopenharmony_ci      }
5627e41f4b71Sopenharmony_ci      .width('100%')
5628e41f4b71Sopenharmony_ci    }
5629e41f4b71Sopenharmony_ci    .height('100%')
5630e41f4b71Sopenharmony_ci  }
5631e41f4b71Sopenharmony_ci}
5632e41f4b71Sopenharmony_ci```
5633e41f4b71Sopenharmony_ci
5634e41f4b71Sopenharmony_ci### gzgets<sup>12+</sup>
5635e41f4b71Sopenharmony_ci
5636e41f4b71Sopenharmony_cigzgets(buf: ArrayBuffer): Promise&lt;string&gt;
5637e41f4b71Sopenharmony_ci
5638e41f4b71Sopenharmony_ci从文件中读取字节并将其解压缩到buf中,直到读取len-1字符,或者直到读取换行符并将其传输到buf,或者遇到文件结束条件。
5639e41f4b71Sopenharmony_ci
5640e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5641e41f4b71Sopenharmony_ci
5642e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
5643e41f4b71Sopenharmony_ci
5644e41f4b71Sopenharmony_ci**参数:**
5645e41f4b71Sopenharmony_ci
5646e41f4b71Sopenharmony_ci| 参数名 | 类型        | 必填 | 说明               |
5647e41f4b71Sopenharmony_ci| ------ | ----------- | ---- | ------------------ |
5648e41f4b71Sopenharmony_ci| buf    | ArrayBuffer | 是   | 存储读取的行数据。 |
5649e41f4b71Sopenharmony_ci
5650e41f4b71Sopenharmony_ci**返回值:**
5651e41f4b71Sopenharmony_ci
5652e41f4b71Sopenharmony_ci| 类型                  | 说明                                  |
5653e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------- |
5654e41f4b71Sopenharmony_ci| Promise&lt;string&gt; | Promise对象,返回以null结尾的字符串。 |
5655e41f4b71Sopenharmony_ci
5656e41f4b71Sopenharmony_ci**错误码:**
5657e41f4b71Sopenharmony_ci
5658e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.zlib错误码](./errorcode-zlib.md)。
5659e41f4b71Sopenharmony_ci
5660e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
5661e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
5662e41f4b71Sopenharmony_ci| 401      | The parameter check failed. Possible causes: <br />1. Mandatory parameters are left unspecified;<br />2. Incorrect parameter types;<br />3. Parameter verification failed. |
5663e41f4b71Sopenharmony_ci| 17800009 | Internal structure error.                                    |
5664e41f4b71Sopenharmony_ci
5665e41f4b71Sopenharmony_ci**示例:**
5666e41f4b71Sopenharmony_ci
5667e41f4b71Sopenharmony_ci```ts
5668e41f4b71Sopenharmony_ciimport { zlib } from '@kit.BasicServicesKit';
5669e41f4b71Sopenharmony_ciimport { fileIo as fs } from '@kit.CoreFileKit';
5670e41f4b71Sopenharmony_ci
5671e41f4b71Sopenharmony_ciasync function gzgetsDemo(pathDir: string) {
5672e41f4b71Sopenharmony_ci  fs.mkdirSync(pathDir + "/gzgets");
5673e41f4b71Sopenharmony_ci  let path = pathDir + "/gzgets/test.gz";
5674e41f4b71Sopenharmony_ci  let gzip = zlib.createGZipSync();
5675e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "wb");
5676e41f4b71Sopenharmony_ci  await gzip.gzputs("hello");
5677e41f4b71Sopenharmony_ci  await gzip.gzclose();
5678e41f4b71Sopenharmony_ci  await gzip.gzopen(path, "rb");
5679e41f4b71Sopenharmony_ci  let bufferWithData = new ArrayBuffer(16);
5680e41f4b71Sopenharmony_ci  let result = await gzip.gzgets(bufferWithData);
5681e41f4b71Sopenharmony_ci  await gzip.gzclose();
5682e41f4b71Sopenharmony_ci}
5683e41f4b71Sopenharmony_ci
5684e41f4b71Sopenharmony_ci@Entry
5685e41f4b71Sopenharmony_ci@Component
5686e41f4b71Sopenharmony_cistruct Index {
5687e41f4b71Sopenharmony_ci  build() {
5688e41f4b71Sopenharmony_ci    Row() {
5689e41f4b71Sopenharmony_ci      Column() {
5690e41f4b71Sopenharmony_ci        Button('test gzip interface')
5691e41f4b71Sopenharmony_ci          .type(ButtonType.Capsule)
5692e41f4b71Sopenharmony_ci          .height(60)
5693e41f4b71Sopenharmony_ci          .width(200)
5694e41f4b71Sopenharmony_ci          .onClick(() => {
5695e41f4b71Sopenharmony_ci            let context = getContext(this);
5696e41f4b71Sopenharmony_ci            let pathDir = context.cacheDir;
5697e41f4b71Sopenharmony_ci            gzgetsDemo(pathDir);
5698e41f4b71Sopenharmony_ci          })
5699e41f4b71Sopenharmony_ci      }
5700e41f4b71Sopenharmony_ci      .width('100%')
5701e41f4b71Sopenharmony_ci    }
5702e41f4b71Sopenharmony_ci    .height('100%')
5703e41f4b71Sopenharmony_ci  }
5704e41f4b71Sopenharmony_ci}
5705e41f4b71Sopenharmony_ci```
5706e41f4b71Sopenharmony_ci
5707e41f4b71Sopenharmony_ci## zip.GzErrorOutputInfo<sup>12+</sup>
5708e41f4b71Sopenharmony_ci
5709e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5710e41f4b71Sopenharmony_ci
5711e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
5712e41f4b71Sopenharmony_ci
5713e41f4b71Sopenharmony_ci| 名称      | 类型         | 可读 | 可写 | 说明                                             |
5714e41f4b71Sopenharmony_ci| --------- | ------------ | ---- | ---- | ------------------------------------------------ |
5715e41f4b71Sopenharmony_ci| status    | ReturnStatus | 是   | 否   | 返回zlib文件状态码,参考zip.ReturnStatus的定义。 |
5716e41f4b71Sopenharmony_ci| statusMsg | string       | 是   | 否   | zlib文件上发生的最后一个状态的状态消息。         |
5717e41f4b71Sopenharmony_ci
5718e41f4b71Sopenharmony_ci## zip.OffsetReferencePoint<sup>12+</sup>
5719e41f4b71Sopenharmony_ci
5720e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5721e41f4b71Sopenharmony_ci
5722e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.Zlib
5723e41f4b71Sopenharmony_ci
5724e41f4b71Sopenharmony_ci| 名称     | 值   | 说明             |
5725e41f4b71Sopenharmony_ci| -------- | ---- | ---------------- |
5726e41f4b71Sopenharmony_ci| SEEK_SET | 0    | 从文件开头查找。 |
5727e41f4b71Sopenharmony_ci| SEEK_CUR | 1    | 从当前位置查找。 |