1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"), 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit BasicServicesKit 19 */ 20 21import { AsyncCallback } from './@ohos.base'; 22 23/** 24 * @namespace zlib 25 * @syscap SystemCapability.BundleManager.Zlib 26 * @since 7 27 */ 28/** 29 * @namespace zlib 30 * @syscap SystemCapability.BundleManager.Zlib 31 * @atomicservice 32 * @since 11 33 */ 34declare namespace zlib { 35 /** 36 * ErrorCode 37 * 38 * @enum { number } 39 * @syscap SystemCapability.BundleManager.Zlib 40 * @since 7 41 * @deprecated since 9 42 */ 43 export enum ErrorCode { 44 /** 45 * @syscap SystemCapability.BundleManager.Zlib 46 * @since 7 47 * @deprecated since 9 48 */ 49 ERROR_CODE_OK = 0, 50 /** 51 * @syscap SystemCapability.BundleManager.Zlib 52 * @since 7 53 * @deprecated since 9 54 */ 55 ERROR_CODE_ERRNO = -1 56 } 57 58 /** 59 * CompressLevel 60 * 61 * @enum { number } 62 * @syscap SystemCapability.BundleManager.Zlib 63 * @since 7 64 */ 65 /** 66 * CompressLevel 67 * 68 * @enum { number } 69 * @syscap SystemCapability.BundleManager.Zlib 70 * @crossplatform 71 * @atomicservice 72 * @since 11 73 */ 74 export enum CompressLevel { 75 /** 76 * Indicates the no compression mode. 77 * 78 * @syscap SystemCapability.BundleManager.Zlib 79 * @since 7 80 */ 81 /** 82 * Indicates the no compression mode. 83 * 84 * @syscap SystemCapability.BundleManager.Zlib 85 * @crossplatform 86 * @atomicservice 87 * @since 11 88 */ 89 COMPRESS_LEVEL_NO_COMPRESSION = 0, 90 /** 91 * Indicates the best speed mode. 92 * 93 * @syscap SystemCapability.BundleManager.Zlib 94 * @since 7 95 */ 96 /** 97 * Indicates the best speed mode. 98 * 99 * @syscap SystemCapability.BundleManager.Zlib 100 * @crossplatform 101 * @atomicservice 102 * @since 11 103 */ 104 COMPRESS_LEVEL_BEST_SPEED = 1, 105 /** 106 * Indicates the best compression mode. 107 * 108 * @syscap SystemCapability.BundleManager.Zlib 109 * @since 7 110 */ 111 /** 112 * Indicates the best compression mode. 113 * 114 * @syscap SystemCapability.BundleManager.Zlib 115 * @crossplatform 116 * @atomicservice 117 * @since 11 118 */ 119 COMPRESS_LEVEL_BEST_COMPRESSION = 9, 120 /** 121 * Indicates the default compression mode. 122 * 123 * @syscap SystemCapability.BundleManager.Zlib 124 * @since 7 125 */ 126 /** 127 * Indicates the default compression mode. 128 * 129 * @syscap SystemCapability.BundleManager.Zlib 130 * @crossplatform 131 * @atomicservice 132 * @since 11 133 */ 134 COMPRESS_LEVEL_DEFAULT_COMPRESSION = -1 135 } 136 137 /** 138 * CompressStrategy 139 * 140 * @enum { number } 141 * @syscap SystemCapability.BundleManager.Zlib 142 * @since 7 143 */ 144 /** 145 * CompressStrategy 146 * 147 * @enum { number } 148 * @syscap SystemCapability.BundleManager.Zlib 149 * @crossplatform 150 * @atomicservice 151 * @since 11 152 */ 153 export enum CompressStrategy { 154 /** 155 * Indicates the default strategy. 156 * 157 * @syscap SystemCapability.BundleManager.Zlib 158 * @since 7 159 */ 160 /** 161 * Indicates the default strategy. 162 * 163 * @syscap SystemCapability.BundleManager.Zlib 164 * @crossplatform 165 * @atomicservice 166 * @since 11 167 */ 168 COMPRESS_STRATEGY_DEFAULT_STRATEGY = 0, 169 /** 170 * Indicates the filtered strategy. 171 * 172 * @syscap SystemCapability.BundleManager.Zlib 173 * @since 7 174 */ 175 /** 176 * Indicates the filtered strategy. 177 * 178 * @syscap SystemCapability.BundleManager.Zlib 179 * @crossplatform 180 * @atomicservice 181 * @since 11 182 */ 183 COMPRESS_STRATEGY_FILTERED = 1, 184 /** 185 * Indicates the huffman-only strategy. 186 * 187 * @syscap SystemCapability.BundleManager.Zlib 188 * @since 7 189 */ 190 /** 191 * Indicates the huffman-only strategy. 192 * 193 * @syscap SystemCapability.BundleManager.Zlib 194 * @crossplatform 195 * @atomicservice 196 * @since 11 197 */ 198 COMPRESS_STRATEGY_HUFFMAN_ONLY = 2, 199 /** 200 * Indicates the RLE strategy. 201 * 202 * @syscap SystemCapability.BundleManager.Zlib 203 * @since 7 204 */ 205 /** 206 * Indicates the RLE strategy. 207 * 208 * @syscap SystemCapability.BundleManager.Zlib 209 * @crossplatform 210 * @atomicservice 211 * @since 11 212 */ 213 COMPRESS_STRATEGY_RLE = 3, 214 /** 215 * Indicates the fixed strategy. 216 * 217 * @syscap SystemCapability.BundleManager.Zlib 218 * @since 7 219 */ 220 /** 221 * Indicates the fixed strategy. 222 * 223 * @syscap SystemCapability.BundleManager.Zlib 224 * @crossplatform 225 * @atomicservice 226 * @since 11 227 */ 228 COMPRESS_STRATEGY_FIXED = 4 229 } 230 231 /** 232 * MemLevel 233 * 234 * @enum { number } 235 * @syscap SystemCapability.BundleManager.Zlib 236 * @since 7 237 */ 238 /** 239 * MemLevel 240 * 241 * @enum { number } 242 * @syscap SystemCapability.BundleManager.Zlib 243 * @crossplatform 244 * @atomicservice 245 * @since 11 246 */ 247 export enum MemLevel { 248 /** 249 * Uses the least amount of memory. 250 * 251 * @syscap SystemCapability.BundleManager.Zlib 252 * @since 7 253 */ 254 /** 255 * Uses the least amount of memory. 256 * 257 * @syscap SystemCapability.BundleManager.Zlib 258 * @crossplatform 259 * @atomicservice 260 * @since 11 261 */ 262 MEM_LEVEL_MIN = 1, 263 /** 264 * Uses the maximum amount of memory. 265 * 266 * @syscap SystemCapability.BundleManager.Zlib 267 * @since 7 268 */ 269 /** 270 * Uses the maximum amount of memory. 271 * 272 * @syscap SystemCapability.BundleManager.Zlib 273 * @crossplatform 274 * @atomicservice 275 * @since 11 276 */ 277 MEM_LEVEL_MAX = 9, 278 /** 279 * Uses the default amount of memory. 280 * 281 * @syscap SystemCapability.BundleManager.Zlib 282 * @since 7 283 */ 284 /** 285 * Uses the default amount of memory. 286 * 287 * @syscap SystemCapability.BundleManager.Zlib 288 * @crossplatform 289 * @atomicservice 290 * @since 11 291 */ 292 MEM_LEVEL_DEFAULT = 8 293 } 294 295 /** 296 * Defines compress or decompress options. 297 * 298 * @typedef Options 299 * @syscap SystemCapability.BundleManager.Zlib 300 * @since 7 301 */ 302 /** 303 * Defines compress or decompress options. 304 * 305 * @typedef Options 306 * @syscap SystemCapability.BundleManager.Zlib 307 * @crossplatform 308 * @atomicservice 309 * @since 11 310 */ 311 interface Options { 312 /** 313 * Indicates the compress level. 314 * 315 * @syscap SystemCapability.BundleManager.Zlib 316 * @since 7 317 */ 318 /** 319 * Indicates the compress level. 320 * 321 * @syscap SystemCapability.BundleManager.Zlib 322 * @crossplatform 323 * @atomicservice 324 * @since 11 325 */ 326 level?: CompressLevel; 327 /** 328 * Indicates the memory level. 329 * 330 * @syscap SystemCapability.BundleManager.Zlib 331 * @since 7 332 */ 333 /** 334 * Indicates the memory level. 335 * 336 * @syscap SystemCapability.BundleManager.Zlib 337 * @crossplatform 338 * @atomicservice 339 * @since 11 340 */ 341 memLevel?: MemLevel; 342 /** 343 * Indicates the compress strategy. 344 * 345 * @syscap SystemCapability.BundleManager.Zlib 346 * @since 7 347 */ 348 /** 349 * Indicates the compress strategy. 350 * 351 * @syscap SystemCapability.BundleManager.Zlib 352 * @crossplatform 353 * @atomicservice 354 * @since 11 355 */ 356 strategy?: CompressStrategy; 357 } 358 359 /** 360 * Compress the specified file. 361 * 362 * @param { string } inFile Indicates the path of the file to be compressed. 363 * @param { string } outFile Indicates the path of the output compressed file. 364 * @param { Options } options 365 * @returns { Promise<void> } 366 * @syscap SystemCapability.BundleManager.Zlib 367 * @since 7 368 * @deprecated since 9 369 * @useinstead ohos.zlib#compressFile 370 */ 371 function zipFile(inFile: string, outFile: string, options: Options): Promise<void>; 372 373 /** 374 * Decompress the specified file. 375 * 376 * @param { string } inFile Indicates the path of the file to be decompressed. 377 * @param { string } outFile Indicates the path of the decompressed file. 378 * @param { Options } options 379 * @returns { Promise<void> } 380 * @syscap SystemCapability.BundleManager.Zlib 381 * @since 7 382 * @deprecated since 9 383 * @useinstead ohos.zlib#decompressFile 384 */ 385 function unzipFile(inFile: string, outFile: string, options: Options): Promise<void>; 386 387 /** 388 * Compress the specified file. 389 * 390 * @param { string } inFile - Indicates the path of the file to be compressed. 391 * @param { string } outFile - Indicates the path of the output compressed file. 392 * @param { Options } options - Indicates the options of compressing file. 393 * @param { AsyncCallback<void> } callback - The callback of compressing file result. 394 * @throws { BusinessError } 401 - The parameter check failed. 395 * @throws { BusinessError } 900001 - The input source file is invalid. 396 * @throws { BusinessError } 900002 - The input destination file is invalid. 397 * @syscap SystemCapability.BundleManager.Zlib 398 * @since 9 399 */ 400 /** 401 * Compress the specified file. 402 * 403 * @param { string } inFile - Indicates the path of the file to be compressed. 404 * @param { string } outFile - Indicates the path of the output compressed file. 405 * @param { Options } options - Indicates the options of compressing file. 406 * @param { AsyncCallback<void> } callback - The callback of compressing file result. 407 * @throws { BusinessError } 401 - The parameter check failed. 408 * @throws { BusinessError } 900001 - The input source file is invalid. 409 * @throws { BusinessError } 900002 - The input destination file is invalid. 410 * @syscap SystemCapability.BundleManager.Zlib 411 * @crossplatform 412 * @atomicservice 413 * @since 11 414 */ 415 function compressFile(inFile: string, outFile: string, options: Options, callback: AsyncCallback<void>): void; 416 417 /** 418 * Compress the specified file. 419 * 420 * @param { string } inFile - Indicates the path of the file to be compressed. 421 * @param { string } outFile - Indicates the path of the output compressed file. 422 * @param { Options } options - Indicates the options of compressing file. 423 * @returns { Promise<void> } Returns the result of compressFile file. 424 * @throws { BusinessError } 401 - The parameter check failed. 425 * @throws { BusinessError } 900001 - The input source file is invalid. 426 * @throws { BusinessError } 900002 - The input destination file is invalid. 427 * @syscap SystemCapability.BundleManager.Zlib 428 * @since 9 429 */ 430 /** 431 * Compress the specified file. 432 * 433 * @param { string } inFile - Indicates the path of the file to be compressed. 434 * @param { string } outFile - Indicates the path of the output compressed file. 435 * @param { Options } options - Indicates the options of compressing file. 436 * @returns { Promise<void> } Returns the result of compressFile file. 437 * @throws { BusinessError } 401 - The parameter check failed. 438 * @throws { BusinessError } 900001 - The input source file is invalid. 439 * @throws { BusinessError } 900002 - The input destination file is invalid. 440 * @syscap SystemCapability.BundleManager.Zlib 441 * @crossplatform 442 * @atomicservice 443 * @since 11 444 */ 445 function compressFile(inFile: string, outFile: string, options: Options): Promise<void>; 446 447 /** 448 * Decompress the specified file. 449 * 450 * @param { string } inFile - Indicates the path of the file to be decompressed. 451 * @param { string } outFile - Indicates the path of the output decompressed file. 452 * @param { Options } options - Indicates the options of decompressing file. 453 * @param { AsyncCallback<void> } callback - The callback of decompressing file result. 454 * @throws { BusinessError } 401 - The parameter check failed. 455 * @throws { BusinessError } 900001 - The input source file is invalid. 456 * @throws { BusinessError } 900002 - The input destination file is invalid. 457 * @syscap SystemCapability.BundleManager.Zlib 458 * @since 9 459 */ 460 /** 461 * Decompress the specified file. 462 * 463 * @param { string } inFile - Indicates the path of the file to be decompressed. 464 * @param { string } outFile - Indicates the path of the output decompressed file. 465 * @param { Options } options - Indicates the options of decompressing file. 466 * @param { AsyncCallback<void> } callback - The callback of decompressing file result. 467 * @throws { BusinessError } 401 - The parameter check failed. 468 * @throws { BusinessError } 900001 - The input source file is invalid. 469 * @throws { BusinessError } 900002 - The input destination file is invalid. 470 * @throws { BusinessError } 900003 - The input source file is not ZIP format or damaged. 471 * @syscap SystemCapability.BundleManager.Zlib 472 * @since 10 473 */ 474 /** 475 * Decompress the specified file. 476 * 477 * @param { string } inFile - Indicates the path of the file to be decompressed. 478 * @param { string } outFile - Indicates the path of the output decompressed file. 479 * @param { Options } options - Indicates the options of decompressing file. 480 * @param { AsyncCallback<void> } callback - The callback of decompressing file result. 481 * @throws { BusinessError } 401 - The parameter check failed. 482 * @throws { BusinessError } 900001 - The input source file is invalid. 483 * @throws { BusinessError } 900002 - The input destination file is invalid. 484 * @throws { BusinessError } 900003 - The input source file is not ZIP format or damaged. 485 * @syscap SystemCapability.BundleManager.Zlib 486 * @crossplatform 487 * @atomicservice 488 * @since 11 489 */ 490 function decompressFile(inFile: string, outFile: string, options: Options, callback: AsyncCallback<void>): void; 491 492 /** 493 * Decompress the specified file. 494 * 495 * @param { string } inFile - Indicates the path of the file to be decompressed. 496 * @param { string } outFile - Indicates the path of the output decompressed file. 497 * @param { AsyncCallback<void> } callback - The callback of decompressing file result. 498 * @throws { BusinessError } 401 - The parameter check failed. 499 * @throws { BusinessError } 900001 - The input source file is invalid. 500 * @throws { BusinessError } 900002 - The input destination file is invalid. 501 * @throws { BusinessError } 900003 - The input source file is not ZIP format or damaged. 502 * @syscap SystemCapability.BundleManager.Zlib 503 * @since 10 504 */ 505 /** 506 * Decompress the specified file. 507 * 508 * @param { string } inFile - Indicates the path of the file to be decompressed. 509 * @param { string } outFile - Indicates the path of the output decompressed file. 510 * @param { AsyncCallback<void> } callback - The callback of decompressing file result. 511 * @throws { BusinessError } 401 - The parameter check failed. 512 * @throws { BusinessError } 900001 - The input source file is invalid. 513 * @throws { BusinessError } 900002 - The input destination file is invalid. 514 * @throws { BusinessError } 900003 - The input source file is not ZIP format or damaged. 515 * @syscap SystemCapability.BundleManager.Zlib 516 * @crossplatform 517 * @atomicservice 518 * @since 11 519 */ 520 function decompressFile(inFile: string, outFile: string, callback: AsyncCallback<void>): void; 521 522 /** 523 * Decompress the specified file. 524 * 525 * @param { string } inFile - Indicates the path of the file to be decompressed. 526 * @param { string } outFile - Indicates the path of the output decompressing file. 527 * @param { Options } options - Indicates the options of decompressing file. 528 * @returns { Promise<void> } Returns the result of decompressing file. 529 * @throws { BusinessError } 401 - The parameter check failed. 530 * @throws { BusinessError } 900001 - The input source file is invalid. 531 * @throws { BusinessError } 900002 - The input destination file is invalid. 532 * @syscap SystemCapability.BundleManager.Zlib 533 * @since 9 534 */ 535 /** 536 * Decompress the specified file. 537 * 538 * @param { string } inFile - Indicates the path of the file to be decompressed. 539 * @param { string } outFile - Indicates the path of the output decompressing file. 540 * @param { Options } options - Indicates the options of decompressing file. 541 * @returns { Promise<void> } Returns the result of decompressing file. 542 * @throws { BusinessError } 401 - The parameter check failed. 543 * @throws { BusinessError } 900001 - The input source file is invalid. 544 * @throws { BusinessError } 900002 - The input destination file is invalid. 545 * @throws { BusinessError } 900003 - The input source file is not ZIP format or damaged. 546 * @syscap SystemCapability.BundleManager.Zlib 547 * @since 10 548 */ 549 /** 550 * Decompress the specified file. 551 * 552 * @param { string } inFile - Indicates the path of the file to be decompressed. 553 * @param { string } outFile - Indicates the path of the output decompressing file. 554 * @param { Options } options - Indicates the options of decompressing file. 555 * @returns { Promise<void> } Returns the result of decompressing file. 556 * @throws { BusinessError } 401 - The parameter check failed. 557 * @throws { BusinessError } 900001 - The input source file is invalid. 558 * @throws { BusinessError } 900002 - The input destination file is invalid. 559 * @throws { BusinessError } 900003 - The input source file is not ZIP format or damaged. 560 * @syscap SystemCapability.BundleManager.Zlib 561 * @crossplatform 562 * @atomicservice 563 * @since 11 564 */ 565 function decompressFile(inFile: string, outFile: string, options?: Options): Promise<void>; 566} 567export default zlib; 568