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