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 "napi/native_api.h"
17 #include "napi/native_node_api.h"
18
19 extern const char _binary_streamhash_js_start[];
20 extern const char _binary_streamhash_js_end[];
21 extern const char _binary_streamhash_abc_start[];
22 extern const char _binary_streamhash_abc_end[];
23
Init(napi_env env,napi_value exports)24 static napi_value Init(napi_env env, napi_value exports)
25 {
26 return exports;
27 }
28
29 extern "C"
NAPI_file_streamhash_GetJSCode(const char ** buf,int * bufLen)30 __attribute__((visibility("default"))) void NAPI_file_streamhash_GetJSCode(const char **buf, int *bufLen)
31 {
32 if (buf != nullptr) {
33 *buf = _binary_streamhash_js_start;
34 }
35
36 if (bufLen != nullptr) {
37 *bufLen = _binary_streamhash_js_end - _binary_streamhash_js_start;
38 }
39 }
40 extern "C"
NAPI_file_streamhash_GetABCCode(const char ** buf,int * buflen)41 __attribute__((visibility("default"))) void NAPI_file_streamhash_GetABCCode(const char** buf, int* buflen)
42 {
43 if (buf != nullptr) {
44 *buf = _binary_streamhash_abc_start;
45 }
46 if (buflen != nullptr) {
47 *buflen = _binary_streamhash_abc_end - _binary_streamhash_abc_start;
48 }
49 }
50
51 static napi_module_with_js streamhashModule = {
52 .nm_version = 1,
53 .nm_flags = 0,
54 .nm_filename = nullptr,
55 .nm_register_func = Init,
56 .nm_modname = "streamhash",
57 .nm_priv = ((void*)0),
58 .nm_get_abc_code = NAPI_file_streamhash_GetABCCode,
59 .nm_get_js_code = NAPI_file_streamhash_GetJSCode,
60 };
61
StreamhashRegisterModule()62 extern "C" __attribute__ ((constructor)) void StreamhashRegisterModule()
63 {
64 napi_module_with_js_register(&streamhashModule);
65 }
66