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