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