1 /*
2  * Copyright (c) 2022 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 #ifndef OHOS_APPEXECFWK_LIBZIP_COMMON_H
16 #define OHOS_APPEXECFWK_LIBZIP_COMMON_H
17 #include <memory>
18 #include <string>
19 
20 #include "napi/native_api.h"
21 #include "napi/native_common.h"
22 #include "napi/native_node_api.h"
23 #include "zlib_callback_info.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 namespace LIBZIP {
28 #define NAPI_CALL_BASE_BOOL(theCall, retVal) \
29     do {                                     \
30         if ((theCall) == false) {            \
31             return retVal;                   \
32         }                                    \
33     } while (0)
34 
35 struct CallZipUnzipParam {
36     std::string src;
37     std::vector<std::string> srcFiles;
38     std::string dest;
39     OPTIONS options;
40 };
41 
42 struct AsyncZipCallbackInfo {
43     napi_async_work asyncWork;
44     CallZipUnzipParam param;
45     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo;
46     int executeResult = 0;
47 };
48 bool UnwrapIntValue(napi_env env, napi_value jsValue, int &result);
49 bool IsTypeForNapiValue(napi_env env, napi_value param, napi_valuetype expectType);
50 std::string UnwrapStringFromJS(napi_env env, napi_value param, const std::string &defaultValue);
51 napi_value GetCallbackErrorValue(napi_env env, int errCode);
52 void SetNamedProperty(napi_env env, napi_value obj, const char *propName, const int propValue);
53 
54 }  // namespace LIBZIP
55 }  // namespace AppExecFwk
56 }  // namespace OHOS
57 #endif  // OHOS_APPEXECFWK_LIBZIP_COMMON_H