1 /*
2 * Copyright (c) 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 #include "create_streamhash.h"
17
18 #include "filemgmt_libhilog.h"
19
20 namespace OHOS {
21 namespace FileManagement {
22 namespace ModuleFileIO {
23 using namespace std;
24 using namespace OHOS::FileManagement::LibN;
25 const string HASH_STREAM_CLASS = "HashStream";
26
Hash(napi_env env,napi_callback_info info)27 napi_value CreateStreamHash::Hash(napi_env env, napi_callback_info info)
28 {
29 NFuncArg funcArg(env, info);
30 if (!funcArg.InitArgs(NARG_CNT::ONE)) {
31 HILOGE("Number of arguments unmatched");
32 NError(EINVAL).ThrowErr(env);
33 return nullptr;
34 }
35 const char moduleName[] = "@ohos.file.streamhash";
36 napi_value streamhash;
37 napi_load_module(env, moduleName, &streamhash);
38 napi_value constructor = nullptr;
39 napi_get_named_property(env, streamhash, HASH_STREAM_CLASS.c_str(), &constructor);
40 napi_value streamObj = nullptr;
41
42 napi_value argv[NARG_CNT::ONE] = {funcArg[NARG_POS::FIRST]};
43 napi_status status = napi_new_instance(env, constructor, NARG_CNT::ONE, argv, &streamObj);
44 if (status != napi_ok) {
45 HILOGE("create stream obj fail");
46 return nullptr;
47 }
48 return NVal(env, streamObj).val_;
49 }
50 } // namespace ModuleFileIO
51 } // namespace FileManagement
52 } // namespace OHOS