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_ZLIB_H
16 #define OHOS_APPEXECFWK_LIBZIP_ZLIB_H
17 #include <string>
18 
19 #include "napi_arg.h"
20 #include "napi/native_api.h"
21 #include "napi_zlib_common.h"
22 #include "zip_utils.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 namespace LIBZIP {
27 
28 /**
29  * @brief FlushType data initialization.
30  *
31  * @param env The environment that the Node-API call is invoked under.
32  * @param exports An empty object via the exports parameter as a convenience.
33  *
34  * @return The return value from Init is treated as the exports object for the module.
35  */
36 napi_value FlushTypeInit(napi_env env, napi_value exports);
37 /**
38  * @brief CompressLevel data initialization.
39  *
40  * @param env The environment that the Node-API call is invoked under.
41  * @param exports An empty object via the exports parameter as a convenience.
42  *
43  * @return The return value from Init is treated as the exports object for the module.
44  */
45 napi_value CompressLevelInit(napi_env env, napi_value exports);
46 
47 /**
48  * @brief CompressFlushModeInit data initialization.
49  *
50  * @param env The environment that the Node-API call is invoked under.
51  * @param exports An empty object via the exports parameter as a convenience.
52  *
53  * @return The return value from Init is treated as the exports object for the module.
54  */
55 napi_value CompressFlushModeInit(napi_env env, napi_value exports);
56 
57 /**
58  * @brief CompressMethodInit data initialization.
59  *
60  * @param env The environment that the Node-API call is invoked under.
61  * @param exports An empty object via the exports parameter as a convenience.
62  *
63  * @return The return value from Init is treated as the exports object for the module.
64  */
65 napi_value CompressMethodInit(napi_env env, napi_value exports);
66 
67 /**
68  * @brief CompressStrategy data initialization.
69  *
70  * @param env The environment that the Node-API call is invoked under.
71  * @param exports An empty object via the exports parameter as a convenience.
72  *
73  * @return The return value from Init is treated as the exports object for the module.
74  */
75 napi_value CompressStrategyInit(napi_env env, napi_value exports);
76 
77 /**
78  * @brief MemLevel data initialization.
79  *
80  * @param env The environment that the Node-API call is invoked under.
81  * @param exports An empty object via the exports parameter as a convenience.
82  *
83  * @return The return value from Init is treated as the exports object for the module.
84  */
85 napi_value MemLevelInit(napi_env env, napi_value exports);
86 
87 /**
88  * @brief OffsetReferencePointInit data initialization.
89  *
90  * @param env The environment that the Node-API call is invoked under.
91  * @param exports An empty object via the exports parameter as a convenience.
92  *
93  * @return The return value from Init is treated as the exports object for the module.
94  */
95 napi_value OffsetReferencePointInit(napi_env env, napi_value exports);
96 
97 /**
98  * @brief ReturnStatusInit data initialization.
99  *
100  * @param env The environment that the Node-API call is invoked under.
101  * @param exports An empty object via the exports parameter as a convenience.
102  *
103  * @return The return value from Init is treated as the exports object for the module.
104  */
105 napi_value ReturnStatusInit(napi_env env, napi_value exports);
106 
107 /**
108  * @brief Errorcode data initialization.
109  *
110  * @param env The environment that the Node-API call is invoked under.
111  * @param exports An empty object via the exports parameter as a convenience.
112  *
113  * @return The return value from Init is treated as the exports object for the module.
114  */
115 napi_value ErrorCodeInit(napi_env env, napi_value exports);
116 /**
117  * @brief zlib NAPI module registration.
118  *
119  * @param env The environment that the Node-API call is invoked under.
120  * @param exports An empty object via the exports parameter as a convenience.
121  *
122  * @return The return value from Init is treated as the exports object for the module.
123  */
124 napi_value ZlibInit(napi_env env, napi_value exports);
125 
126 /**
127  * @brief Zlib NAPI method : zipFile.
128  *
129  * @param env The environment that the Node-API call is invoked under.
130  * @param info The callback info passed into the callback function.
131  *
132  * @return The return value from NAPI C++ to JS for the module.
133  *
134  * NAPI_Zipfile interface supports promise and callback calls.
135  *
136  * example No1
137  * var src ="/ziptest/zipdata/";
138  * var dest ="/ziptest/hapresult/hapfourfile.zip";
139  * var option = {
140  *           flush:0,
141  *           finishFlush:2,
142  *           chunkSize:68,
143  *           memLevel:8,
144  *           level:-1,
145  *           strategy:0
146  *         };
147  *
148  * example No2
149  * var src ="/ziptest/zipdata/zip1/zip1-1.cpp";
150  * var dest ="/ziptest/hapresult/single.zip";
151  * var option = {
152  *           flush:0,
153  *           finishFlush:2,
154  *           chunkSize:68,
155  *           memLevel:8,
156  *           level:-1,
157  *           strategy:0
158  *       };
159  *
160  */
161 napi_value NAPI_ZipFile(napi_env env, napi_callback_info info);
162 
163 /**
164  * @brief Zlib NAPI method : unzipFile.
165  *
166  * @param env The environment that the Node-API call is invoked under.
167  * @param info The callback info passed into the callback function.
168  *
169  * @return The return value from NAPI C++ to JS for the module.
170  *
171  * NAPI_UnzipFile interface supports promise and callback calls.
172  *
173  * example No1
174  * var src ="/ziptest/hapresult/hapfourfile.zip";
175  * var dest ="/ziptest/hapunzipdir/01";
176  * var option = {
177  *           flush:0,
178  *           finishFlush:2,
179  *           chunkSize:68,
180  *           memLevel:8,
181  *           level:-1,
182  *           strategy:0
183  *       };
184  *
185  * example No2
186  * var src ="/ziptest/hapresult/single.zip";
187  * var dest ="/ziptest/hapunzipdir/single";
188  * var option = {
189  *           flush:0,
190  *           finishFlush:2,
191  *           chunkSize:68,
192  *           memLevel:8,
193  *           level:-1,
194  *           strategy:0
195  *       };
196  */
197 napi_value NAPI_UnzipFile(napi_env env, napi_callback_info info);
198 
199 bool InitParam(CallZipUnzipParam &param, napi_env env, NapiArg &args, bool isZipFile);
200 
201 napi_value CompressFile(napi_env env, napi_callback_info info);
202 napi_value CompressFiles(napi_env env, napi_callback_info info);
203 napi_value DecompressFile(napi_env env, napi_callback_info info);
204 napi_value GetOriginalSize(napi_env env, napi_callback_info info);
205 
206 }  // namespace LIBZIP
207 }  // namespace AppExecFwk
208 }  // namespace OHOS
209 
210 #endif  // OHOS_APPEXECFWK_LIBZIP_ZLIB_H
211