1/* 2 * Copyright (c) 2022-2024 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 CoreFileKit 19 */ 20 21import type { AsyncCallback } from './@ohos.base'; 22import stream from './@ohos.util.stream'; 23 24/** 25 * Hash 26 * 27 * @namespace hash 28 * @syscap SystemCapability.FileManagement.File.FileIO 29 * @since 9 30 */ 31/** 32 * Hash 33 * 34 * @namespace hash 35 * @syscap SystemCapability.FileManagement.File.FileIO 36 * @atomicservice 37 * @since 11 38 */ 39declare namespace hash { 40 /** 41 * Hash file. 42 * 43 * @param { string } path - path. 44 * @param { string } algorithm - algorithm md5 sha1 sha256. 45 * @returns { Promise<string> } return Promise 46 * @throws { BusinessError } 13900020 - Invalid argument 47 * @throws { BusinessError } 13900042 - Unknown error 48 * @syscap SystemCapability.FileManagement.File.FileIO 49 * @since 9 50 */ 51 /** 52 * Hash file. 53 * 54 * @param { string } path - path. 55 * @param { string } algorithm - algorithm md5 sha1 sha256. 56 * @returns { Promise<string> } return Promise 57 * @throws { BusinessError } 13900020 - Invalid argument 58 * @throws { BusinessError } 13900042 - Unknown error 59 * @syscap SystemCapability.FileManagement.File.FileIO 60 * @atomicservice 61 * @since 11 62 */ 63 function hash(path: string, algorithm: string): Promise<string>; 64 65 /** 66 * Hash file. 67 * 68 * @param { string } path - path. 69 * @param { string } algorithm - algorithm md5 sha1 sha256. 70 * @param { AsyncCallback<string> } [callback] - callback. 71 * @throws { BusinessError } 13900020 - Invalid argument 72 * @throws { BusinessError } 13900042 - Unknown error 73 * @syscap SystemCapability.FileManagement.File.FileIO 74 * @since 9 75 */ 76 /** 77 * Hash file. 78 * 79 * @param { string } path - path. 80 * @param { string } algorithm - algorithm md5 sha1 sha256. 81 * @param { AsyncCallback<string> } [callback] - callback. 82 * @throws { BusinessError } 13900020 - Invalid argument 83 * @throws { BusinessError } 13900042 - Unknown error 84 * @syscap SystemCapability.FileManagement.File.FileIO 85 * @atomicservice 86 * @since 11 87 */ 88 function hash(path: string, algorithm: string, callback: AsyncCallback<string>): void; 89 90 /** 91 * Hash Stream. 92 * 93 * @extends stream.Transform 94 * @syscap SystemCapability.FileManagement.File.FileIO 95 * @since 12 96 */ 97 class HashStream extends stream.Transform { 98 /** 99 * Calculate the digest of all of the data passed to be hashed. 100 * 101 * @returns { string } Returns the hexadecimal data string of the hash result. 102 * @throws { BusinessError } 401 - Parameter error 103 * @throws { BusinessError } 13900042 - Unknown error 104 * @syscap SystemCapability.FileManagement.File.FileIO 105 * @since 12 106 */ 107 digest(): string; 108 109 /** 110 * Update the hash content with the given data. 111 * 112 * @param { ArrayBuffer } data - updated data. 113 * @throws { BusinessError } 401 - Parameter error 114 * @throws { BusinessError } 13900042 - Unknown error 115 * @syscap SystemCapability.FileManagement.File.FileIO 116 * @since 12 117 */ 118 update(data: ArrayBuffer): void; 119 } 120 121/** 122 * Create file read stream. 123 * 124 * @param { string } algorithm - hash algorithm. 125 * @returns { HashStream } Returns the ReadStream object which has been created. 126 * @throws { BusinessError } 401 - Parameter error 127 * @throws { BusinessError } 13900020 - Invalid argument 128 * @throws { BusinessError } 13900042 - Unknown error 129 * @syscap SystemCapability.FileManagement.File.FileIO 130 * @since 12 131 */ 132 function createHash(algorithm: string): HashStream; 133} 134 135export default hash; 136