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