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