• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2025 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';
22/*** if arkts 1.1 */
23import stream from './@ohos.util.stream';
24/*** endif */
25
26/**
27 * Hash
28 *
29 * @namespace hash
30 * @syscap SystemCapability.FileManagement.File.FileIO
31 * @since 9
32 */
33/**
34 * Hash
35 *
36 * @namespace hash
37 * @syscap SystemCapability.FileManagement.File.FileIO
38 * @atomicservice
39 * @since 11
40 */
41/**
42 * Hash
43 *
44 * @namespace hash
45 * @syscap SystemCapability.FileManagement.File.FileIO
46 * @crossplatform
47 * @atomicservice
48 * @since 20
49 * @arkts 1.1&1.2
50 */
51declare namespace hash {
52  /**
53   * Hash file.
54   *
55   * @param { string } path - path.
56   * @param { string } algorithm - algorithm md5 sha1 sha256.
57   * @returns { Promise<string> } return Promise
58   * @throws { BusinessError } 13900020 - Invalid argument
59   * @throws { BusinessError } 13900042 - Unknown error
60   * @syscap SystemCapability.FileManagement.File.FileIO
61   * @since 9
62   */
63  /**
64   * Hash file.
65   *
66   * @param { string } path - path.
67   * @param { string } algorithm - algorithm md5 sha1 sha256.
68   * @returns { Promise<string> } return Promise
69   * @throws { BusinessError } 13900020 - Invalid argument
70   * @throws { BusinessError } 13900042 - Unknown error
71   * @syscap SystemCapability.FileManagement.File.FileIO
72   * @atomicservice
73   * @since 11
74   */
75  /**
76   * Hash file.
77   *
78   * @param { string } path - path.
79   * @param { string } algorithm - algorithm md5 sha1 sha256.
80   * @returns { Promise<string> } return Promise
81   * @throws { BusinessError } 13900020 - Invalid argument
82   * @throws { BusinessError } 13900042 - Unknown error
83   * @syscap SystemCapability.FileManagement.File.FileIO
84   * @crossplatform
85   * @atomicservice
86   * @since 20
87   * @arkts 1.1&1.2
88   */
89  function hash(path: string, algorithm: string): Promise<string>;
90
91  /**
92   * Hash file.
93   *
94   * @param { string } path - path.
95   * @param { string } algorithm - algorithm md5 sha1 sha256.
96   * @param { AsyncCallback<string> } [callback] - callback.
97   * @throws { BusinessError } 13900020 - Invalid argument
98   * @throws { BusinessError } 13900042 - Unknown error
99   * @syscap SystemCapability.FileManagement.File.FileIO
100   * @since 9
101   */
102  /**
103   * Hash file.
104   *
105   * @param { string } path - path.
106   * @param { string } algorithm - algorithm md5 sha1 sha256.
107   * @param { AsyncCallback<string> } [callback] - callback.
108   * @throws { BusinessError } 13900020 - Invalid argument
109   * @throws { BusinessError } 13900042 - Unknown error
110   * @syscap SystemCapability.FileManagement.File.FileIO
111   * @atomicservice
112   * @since 11
113   */
114  /**
115   * Hash file.
116   *
117   * @param { string } path - path.
118   * @param { string } algorithm - algorithm md5 sha1 sha256.
119   * @param { AsyncCallback<string> } [callback] - callback.
120   * @throws { BusinessError } 13900020 - Invalid argument
121   * @throws { BusinessError } 13900042 - Unknown error
122   * @syscap SystemCapability.FileManagement.File.FileIO
123   * @crossplatform
124   * @atomicservice
125   * @since 20
126   * @arkts 1.1&1.2
127   */
128  function hash(path: string, algorithm: string, callback: AsyncCallback<string>): void;
129
130  /**
131   * Hash Stream.
132   *
133   * @extends stream.Transform
134   * @syscap SystemCapability.FileManagement.File.FileIO
135   * @since 12
136   */
137  /**
138   * Hash Stream.
139   *
140   * @extends stream.Transform
141   * @syscap SystemCapability.FileManagement.File.FileIO
142   * @crossplatform
143   * @since 20
144   */
145  class HashStream extends stream.Transform {
146    /**
147     * Calculate the digest of all of the data passed to be hashed.
148     *
149     * @returns { string } Returns the hexadecimal data string of the hash result.
150     * @throws { BusinessError } 401 - Parameter error
151     * @throws { BusinessError } 13900042 - Unknown error
152     * @syscap SystemCapability.FileManagement.File.FileIO
153     * @since 12
154     */
155    /**
156     * Calculate the digest of all of the data passed to be hashed.
157     *
158     * @returns { string } Returns the hexadecimal data string of the hash result.
159     * @throws { BusinessError } 401 - Parameter error
160     * @throws { BusinessError } 13900042 - Unknown error
161     * @syscap SystemCapability.FileManagement.File.FileIO
162     * @crossplatform
163     * @since 20
164     */
165    digest(): string;
166
167    /**
168     * Update the hash content with the given data.
169     *
170     * @param { ArrayBuffer } data - updated data.
171     * @throws { BusinessError } 401 - Parameter error
172     * @throws { BusinessError } 13900042 - Unknown error
173     * @syscap SystemCapability.FileManagement.File.FileIO
174     * @since 12
175     */
176    /**
177     * Update the hash content with the given data.
178     *
179     * @param { ArrayBuffer } data - updated data.
180     * @throws { BusinessError } 401 - Parameter error
181     * @throws { BusinessError } 13900042 - Unknown error
182     * @syscap SystemCapability.FileManagement.File.FileIO
183     * @crossplatform
184     * @since 20
185     */
186    update(data: ArrayBuffer): void;
187  }
188
189  /**
190   * Create file read stream.
191   *
192   * @param { string } algorithm - hash algorithm.
193   * @returns { HashStream } Returns the ReadStream object which has been created.
194   * @throws { BusinessError } 401 - Parameter error
195   * @throws { BusinessError } 13900020 - Invalid argument
196   * @throws { BusinessError } 13900042 - Unknown error
197   * @syscap SystemCapability.FileManagement.File.FileIO
198   * @since 12
199   */
200  /**
201   * Create file read stream.
202   *
203   * @param { string } algorithm - hash algorithm.
204   * @returns { HashStream } Returns the ReadStream object which has been created.
205   * @throws { BusinessError } 401 - Parameter error
206   * @throws { BusinessError } 13900020 - Invalid argument
207   * @throws { BusinessError } 13900042 - Unknown error
208   * @syscap SystemCapability.FileManagement.File.FileIO
209   * @crossplatform
210   * @since 20
211   */
212  function createHash(algorithm: string): HashStream;
213}
214
215export default hash;
216