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