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 16import { AsyncCallback } from './basic'; 17 18declare namespace zlib { 19/** 20 * @name ErrorCode 21 * @since 7 22 * @syscap SystemCapability.BundleManager.Zlib 23 * @deprecated since 9 24 */ 25 export enum ErrorCode { 26 ERROR_CODE_OK = 0, 27 ERROR_CODE_ERRNO = -1 28 } 29 30/** 31 * @name CompressLevel 32 * @since 7 33 * @syscap SystemCapability.BundleManager.Zlib 34 */ 35 export enum CompressLevel { 36 COMPRESS_LEVEL_NO_COMPRESSION = 0, 37 COMPRESS_LEVEL_BEST_SPEED = 1, 38 COMPRESS_LEVEL_BEST_COMPRESSION = 9, 39 COMPRESS_LEVEL_DEFAULT_COMPRESSION = -1 40 } 41 42/** 43 * @name CompressStrategy 44 * @since 7 45 * @syscap SystemCapability.BundleManager.Zlib 46 */ 47 export enum CompressStrategy { 48 COMPRESS_STRATEGY_DEFAULT_STRATEGY = 0, 49 COMPRESS_STRATEGY_FILTERED = 1, 50 COMPRESS_STRATEGY_HUFFMAN_ONLY = 2, 51 COMPRESS_STRATEGY_RLE = 3, 52 COMPRESS_STRATEGY_FIXED = 4 53 } 54 55/** 56 * @name MemLevel 57 * @since 7 58 * @syscap SystemCapability.BundleManager.Zlib 59 */ 60 export enum MemLevel { 61 MEM_LEVEL_MIN = 1, 62 MEM_LEVEL_MAX = 9, 63 MEM_LEVEL_DEFAULT = 8 64 } 65 66/** 67 * @name Options 68 * @since 7 69 * @syscap SystemCapability.BundleManager.Zlib 70 */ 71 interface Options { 72 level?: CompressLevel; 73 memLevel?: MemLevel; 74 strategy?: CompressStrategy; 75 } 76 77 /** 78 * Compress the specified file. 79 * 80 * @since 7 81 * @syscap SystemCapability.BundleManager.Zlib 82 * @param inFile Indicates the path of the file to be compressed. 83 * @param outFile Indicates the path of the output compressed file. 84 * @returns Returns error code. 85 * @deprecated since 9 86 * @useinstead ohos.zlib#compressFile 87 */ 88 function zipFile(inFile:string, outFile:string, options: Options): Promise<void>; 89 90 /** 91 * Decompress the specified file. 92 * 93 * @since 7 94 * @syscap SystemCapability.BundleManager.Zlib 95 * @param inFile Indicates the path of the file to be decompressed. 96 * @param outFile Indicates the path of the decompressed file. 97 * @returns Returns error code. 98 * @deprecated since 9 99 * @useinstead ohos.zlib#decompressFile 100 */ 101 function unzipFile(inFile:string, outFile:string, options: Options): Promise<void>; 102 103 /** 104 * Compress the specified file. 105 * @param {string} inFile Indicates the path of the file to be compressed. 106 * @param {string} outFile Indicates the path of the output compressed file. 107 * @param {Options} options Indicates the options of compressing file. 108 * @param {AsyncCallback<void>} callback - The callback of compressing file result. 109 * @throws {BusinessError} 401 - The parameter check failed. 110 * @throws {BusinessError} 900001 - The input source file is invalid. 111 * @throws {BusinessError} 900002 - The input destination file is invalid. 112 * @syscap SystemCapability.BundleManager.Zlib 113 * @since 9 114 */ 115 function compressFile(inFile: string, outFile: string, options: Options, callback: AsyncCallback<void>): void; 116 117 /** 118 * Compress the specified file. 119 * @param {string} inFile Indicates the path of the file to be compressed. 120 * @param {string} outFile Indicates the path of the output compressed file. 121 * @param {Options} options Indicates the options of compressing file. 122 * @returns {Promise<void>} Returns the result of compressFile file. 123 * @throws {BusinessError} 401 - The parameter check failed. 124 * @throws {BusinessError} 900001 - The input source file is invalid. 125 * @throws {BusinessError} 900002 - The input destination file is invalid. 126 * @syscap SystemCapability.BundleManager.Zlib 127 * @since 9 128 */ 129 function compressFile(inFile:string, outFile:string, options: Options): Promise<void>; 130 131 /** 132 * Decompress the specified file. 133 * @param {string} inFile Indicates the path of the file to be decompressed. 134 * @param {string} outFile Indicates the path of the output decompressed file. 135 * @param {Options} options Indicates the options of decompressing file. 136 * @param {AsyncCallback<void>} callback - The callback of decompressing file result. 137 * @throws {BusinessError} 401 - The parameter check failed. 138 * @throws {BusinessError} 900001 - The input source file is invalid. 139 * @throws {BusinessError} 900002 - The input destination file is invalid. 140 * @syscap SystemCapability.BundleManager.Zlib 141 * @since 9 142 */ 143 function decompressFile(inFile: string, outFile: string, options: Options, callback: AsyncCallback<void>): void; 144 145 /** 146 * Decompress the specified file. 147 * @param {string} inFile Indicates the path of the file to be decompressed. 148 * @param {string} outFile Indicates the path of the output decompressing file. 149 * @param {Options} options Indicates the options of decompressing file. 150 * @returns {Promise<void>} Returns the result of decompressing file. 151 * @throws {BusinessError} 401 - The parameter check failed. 152 * @throws {BusinessError} 900001 - The input source file is invalid. 153 * @throws {BusinessError} 900002 - The input destination file is invalid. 154 * @syscap SystemCapability.BundleManager.Zlib 155 * @since 9 156 */ 157 function decompressFile(inFile: string, outFile: string, options: Options): Promise<void>; 158 159} 160export default zlib;