react-native-update 10.38.3 → 10.38.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/harmony/pushy/src/main/cpp/CMakeLists.txt +70 -0
- package/harmony/pushy/src/main/cpp/PushyPackage.h +55 -0
- package/harmony/pushy/src/main/cpp/PushyTurboModule.cpp +142 -0
- package/harmony/pushy/src/main/cpp/PushyTurboModule.h +38 -0
- package/harmony/pushy/src/main/cpp/pushy.c +117 -0
- package/harmony/pushy/src/main/cpp/pushy.cpp +856 -0
- package/harmony/pushy/src/main/cpp/pushy.h +8 -0
- package/harmony/pushy/src/main/ets/DownloadTask.ts +610 -0
- package/harmony/pushy/src/main/ets/DownloadTaskParams.ts +19 -0
- package/harmony/pushy/src/main/ets/EventHub.ts +39 -0
- package/harmony/pushy/src/main/ets/Logger.ts +52 -0
- package/harmony/pushy/src/main/ets/NativePatchCore.ts +87 -0
- package/harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets +50 -0
- package/harmony/pushy/src/main/ets/PushyPackage.ts +22 -0
- package/harmony/pushy/src/main/ets/PushyTurboModule.ts +139 -0
- package/harmony/pushy/src/main/ets/SaveFile.ts +34 -0
- package/harmony/pushy/src/main/ets/UpdateContext.ts +346 -0
- package/harmony/pushy/src/main/ets/UpdateModuleImpl.ts +123 -0
- package/harmony/pushy/src/main/module.json5 +7 -0
- package/harmony/pushy/src/main/resources/base/element/string.json +8 -0
- package/harmony/pushy/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/pushy/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/pushy.har +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.13)
|
|
2
|
+
project(rnupdate LANGUAGES C CXX)
|
|
3
|
+
|
|
4
|
+
set(CMAKE_C_STANDARD 11)
|
|
5
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
6
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
7
|
+
|
|
8
|
+
set(PUSHY_MODULE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
|
9
|
+
set(PUSHY_ABI ${CMAKE_OHOS_ARCH_ABI})
|
|
10
|
+
if(NOT PUSHY_ABI)
|
|
11
|
+
set(PUSHY_ABI ${OHOS_ARCH})
|
|
12
|
+
endif()
|
|
13
|
+
set(PREBUILT_RNUPDATE_PATH ${PUSHY_MODULE_ROOT}/libs/${PUSHY_ABI}/librnupdate.so)
|
|
14
|
+
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
15
|
+
|
|
16
|
+
set(REPO_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../)
|
|
17
|
+
set(STAGED_NATIVE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android-generated)
|
|
18
|
+
set(ANDROID_JNI_DIR ${REPO_ROOT}/android/jni)
|
|
19
|
+
if(NOT EXISTS ${ANDROID_JNI_DIR}/hpatch.c)
|
|
20
|
+
set(ANDROID_JNI_DIR ${STAGED_NATIVE_DIR}/jni)
|
|
21
|
+
endif()
|
|
22
|
+
set(PATCH_CORE_DIR ${REPO_ROOT}/cpp/patch_core)
|
|
23
|
+
if(NOT EXISTS ${PATCH_CORE_DIR}/patch_core.cpp)
|
|
24
|
+
set(PATCH_CORE_DIR ${STAGED_NATIVE_DIR}/patch_core)
|
|
25
|
+
endif()
|
|
26
|
+
|
|
27
|
+
if(EXISTS ${PREBUILT_RNUPDATE_PATH})
|
|
28
|
+
add_library(rnupdate SHARED IMPORTED GLOBAL)
|
|
29
|
+
set_target_properties(rnupdate PROPERTIES IMPORTED_LOCATION ${PREBUILT_RNUPDATE_PATH})
|
|
30
|
+
else()
|
|
31
|
+
# When building the HAR itself, native sources are compiled from the repo checkout.
|
|
32
|
+
set(HDIFFPATCH_DIR ${ANDROID_JNI_DIR}/HDiffPatch)
|
|
33
|
+
set(LZMA_DIR ${ANDROID_JNI_DIR}/lzma)
|
|
34
|
+
set(HDP_SOURCES
|
|
35
|
+
${CMAKE_CURRENT_SOURCE_DIR}/pushy.cpp
|
|
36
|
+
${PATCH_CORE_DIR}/archive_patch_core.cpp
|
|
37
|
+
${PATCH_CORE_DIR}/patch_core.cpp
|
|
38
|
+
${PATCH_CORE_DIR}/state_core.cpp
|
|
39
|
+
${ANDROID_JNI_DIR}/hpatch.c
|
|
40
|
+
${HDIFFPATCH_DIR}/libHDiffPatch/HPatch/patch.c
|
|
41
|
+
${HDIFFPATCH_DIR}/file_for_patch.c
|
|
42
|
+
${LZMA_DIR}/C/LzmaDec.c
|
|
43
|
+
${LZMA_DIR}/C/Lzma2Dec.c
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
add_library(rnupdate SHARED
|
|
47
|
+
${HDP_SOURCES}
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
target_include_directories(rnupdate PRIVATE
|
|
51
|
+
${CMAKE_CURRENT_SOURCE_DIR}
|
|
52
|
+
${PATCH_CORE_DIR}
|
|
53
|
+
${ANDROID_JNI_DIR}
|
|
54
|
+
${HDIFFPATCH_DIR}
|
|
55
|
+
${HDIFFPATCH_DIR}/libHDiffPatch/HPatch
|
|
56
|
+
${LZMA_DIR}/C
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
target_link_libraries(rnupdate PUBLIC
|
|
60
|
+
libace_napi.z.so
|
|
61
|
+
)
|
|
62
|
+
endif()
|
|
63
|
+
|
|
64
|
+
if(TARGET rnoh)
|
|
65
|
+
add_library(rnoh_pushy SHARED
|
|
66
|
+
${CMAKE_CURRENT_SOURCE_DIR}/PushyTurboModule.cpp
|
|
67
|
+
)
|
|
68
|
+
target_include_directories(rnoh_pushy PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
|
69
|
+
target_link_libraries(rnoh_pushy PUBLIC rnoh)
|
|
70
|
+
endif()
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#ifndef GEO_LOCATION_PACKAGE_H
|
|
26
|
+
#define GEO_LOCATION_PACKAGE_H
|
|
27
|
+
|
|
28
|
+
#include "RNOH/Package.h"
|
|
29
|
+
#include "PushyTurboModule.h"
|
|
30
|
+
|
|
31
|
+
using namespace rnoh;
|
|
32
|
+
using namespace facebook;
|
|
33
|
+
|
|
34
|
+
class PushyTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
35
|
+
public:
|
|
36
|
+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override
|
|
37
|
+
{
|
|
38
|
+
if (name == "Pushy") {
|
|
39
|
+
return std::make_shared<PushyTurboModule>(ctx, name);
|
|
40
|
+
}
|
|
41
|
+
return nullptr;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
namespace rnoh {
|
|
46
|
+
class PushyPackage : public Package {
|
|
47
|
+
public:
|
|
48
|
+
PushyPackage(Package::Context ctx) : Package(ctx){}
|
|
49
|
+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override
|
|
50
|
+
{
|
|
51
|
+
return std::make_unique<PushyTurboModuleFactoryDelegate>();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
} // namespace rnoh
|
|
55
|
+
#endif
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
|
|
2
|
+
#include "PushyTurboModule.h"
|
|
3
|
+
|
|
4
|
+
using namespace rnoh;
|
|
5
|
+
using namespace facebook;
|
|
6
|
+
|
|
7
|
+
static jsi::Value _hostFunction_PushyTurboModule_getConstants(
|
|
8
|
+
jsi::Runtime &rt,
|
|
9
|
+
react::TurboModule & turboModule,
|
|
10
|
+
const jsi::Value* args,
|
|
11
|
+
size_t count)
|
|
12
|
+
{
|
|
13
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"getConstants", args, count));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static jsi::Value _hostFunction_PushyTurboModule_setLocalHashInfo(
|
|
17
|
+
jsi::Runtime &rt,
|
|
18
|
+
react::TurboModule & turboModule,
|
|
19
|
+
const jsi::Value* args,
|
|
20
|
+
size_t count)
|
|
21
|
+
{
|
|
22
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"setLocalHashInfo", args, count));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static jsi::Value _hostFunction_PushyTurboModule_getLocalHashInfo(
|
|
26
|
+
jsi::Runtime &rt,
|
|
27
|
+
react::TurboModule & turboModule,
|
|
28
|
+
const jsi::Value* args,
|
|
29
|
+
size_t count)
|
|
30
|
+
{
|
|
31
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"getLocalHashInfo", args, count));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static jsi::Value _hostFunction_PushyTurboModule_setUuid(
|
|
35
|
+
jsi::Runtime &rt,
|
|
36
|
+
react::TurboModule & turboModule,
|
|
37
|
+
const jsi::Value* args,
|
|
38
|
+
size_t count)
|
|
39
|
+
{
|
|
40
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"setUuid", args, count));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static jsi::Value _hostFunction_PushyTurboModule_reloadUpdate(
|
|
44
|
+
jsi::Runtime &rt,
|
|
45
|
+
react::TurboModule & turboModule,
|
|
46
|
+
const jsi::Value* args,
|
|
47
|
+
size_t count)
|
|
48
|
+
{
|
|
49
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"reloadUpdate", args, count));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static jsi::Value _hostFunction_PushyTurboModule_setNeedUpdate(
|
|
53
|
+
jsi::Runtime &rt,
|
|
54
|
+
react::TurboModule & turboModule,
|
|
55
|
+
const jsi::Value* args,
|
|
56
|
+
size_t count)
|
|
57
|
+
{
|
|
58
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"setNeedUpdate", args, count));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static jsi::Value _hostFunction_PushyTurboModule_markSuccess(
|
|
62
|
+
jsi::Runtime &rt,
|
|
63
|
+
react::TurboModule & turboModule,
|
|
64
|
+
const jsi::Value* args,
|
|
65
|
+
size_t count)
|
|
66
|
+
{
|
|
67
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"markSuccess", args, count));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static jsi::Value _hostFunction_PushyTurboModule_downloadPatchFromPpk(
|
|
71
|
+
jsi::Runtime &rt,
|
|
72
|
+
react::TurboModule & turboModule,
|
|
73
|
+
const jsi::Value* args,
|
|
74
|
+
size_t count)
|
|
75
|
+
{
|
|
76
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadPatchFromPpk", args, count));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static jsi::Value _hostFunction_PushyTurboModule_downloadPatchFromPackage(
|
|
80
|
+
jsi::Runtime &rt,
|
|
81
|
+
react::TurboModule & turboModule,
|
|
82
|
+
const jsi::Value* args,
|
|
83
|
+
size_t count)
|
|
84
|
+
{
|
|
85
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadPatchFromPackage", args, count));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static jsi::Value _hostFunction_PushyTurboModule_downloadFullUpdate(
|
|
89
|
+
jsi::Runtime &rt,
|
|
90
|
+
react::TurboModule & turboModule,
|
|
91
|
+
const jsi::Value* args,
|
|
92
|
+
size_t count)
|
|
93
|
+
{
|
|
94
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadFullUpdate", args, count));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static jsi::Value _hostFunction_PushyTurboModule_downloadAndInstallApk(
|
|
98
|
+
jsi::Runtime &rt,
|
|
99
|
+
react::TurboModule & turboModule,
|
|
100
|
+
const jsi::Value* args,
|
|
101
|
+
size_t count)
|
|
102
|
+
{
|
|
103
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadAndInstallApk", args, count));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
static jsi::Value _hostFunction_PushyTurboModule_addListener(
|
|
109
|
+
jsi::Runtime &rt,
|
|
110
|
+
react::TurboModule & turboModule,
|
|
111
|
+
const jsi::Value* args,
|
|
112
|
+
size_t count)
|
|
113
|
+
{
|
|
114
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"addListener", args, count));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static jsi::Value _hostFunction_PushyTurboModule_removeListeners(
|
|
118
|
+
jsi::Runtime &rt,
|
|
119
|
+
react::TurboModule & turboModule,
|
|
120
|
+
const jsi::Value* args,
|
|
121
|
+
size_t count)
|
|
122
|
+
{
|
|
123
|
+
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"removeListeners", args, count));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
PushyTurboModule::PushyTurboModule(const ArkTSTurboModule::Context ctx, const std::string name)
|
|
127
|
+
: ArkTSTurboModule(ctx,name)
|
|
128
|
+
{
|
|
129
|
+
methodMap_["getConstants"]= MethodMetadata{1, _hostFunction_PushyTurboModule_getConstants};
|
|
130
|
+
methodMap_["setLocalHashInfo"]= MethodMetadata{2, _hostFunction_PushyTurboModule_setLocalHashInfo};
|
|
131
|
+
methodMap_["getLocalHashInfo"]= MethodMetadata{3, _hostFunction_PushyTurboModule_getLocalHashInfo};
|
|
132
|
+
methodMap_["setUuid"]= MethodMetadata{1, _hostFunction_PushyTurboModule_setUuid};
|
|
133
|
+
methodMap_["reloadUpdate"]= MethodMetadata{0, _hostFunction_PushyTurboModule_reloadUpdate};
|
|
134
|
+
methodMap_["setNeedUpdate"]= MethodMetadata{0, _hostFunction_PushyTurboModule_setNeedUpdate};
|
|
135
|
+
methodMap_["markSuccess"]= MethodMetadata{0, _hostFunction_PushyTurboModule_markSuccess};
|
|
136
|
+
methodMap_["downloadPatchFromPpk"]= MethodMetadata{0, _hostFunction_PushyTurboModule_downloadPatchFromPpk};
|
|
137
|
+
methodMap_["downloadPatchFromPackage"]= MethodMetadata{0, _hostFunction_PushyTurboModule_downloadPatchFromPackage};
|
|
138
|
+
methodMap_["downloadFullUpdate"]= MethodMetadata{0, _hostFunction_PushyTurboModule_downloadFullUpdate};
|
|
139
|
+
methodMap_["downloadAndInstallApk"]= MethodMetadata{0, _hostFunction_PushyTurboModule_downloadAndInstallApk};
|
|
140
|
+
methodMap_["addListener"]= MethodMetadata{1, _hostFunction_PushyTurboModule_addListener};
|
|
141
|
+
methodMap_["removeListeners"]= MethodMetadata{1, _hostFunction_PushyTurboModule_removeListeners};
|
|
142
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#ifndef GEO_LOCATION_TURBOMODULE_H
|
|
26
|
+
#define GEO_LOCATION_TURBOMODULE_H
|
|
27
|
+
|
|
28
|
+
#include <ReactCommon/TurboModule.h>
|
|
29
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
30
|
+
|
|
31
|
+
namespace rnoh {
|
|
32
|
+
class JSI_EXPORT PushyTurboModule : public ArkTSTurboModule {
|
|
33
|
+
public:
|
|
34
|
+
PushyTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
|
|
35
|
+
};
|
|
36
|
+
} // namespace rnoh
|
|
37
|
+
|
|
38
|
+
#endif
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#include "pushy.h"
|
|
2
|
+
#include "hpatch.h"
|
|
3
|
+
#include <napi/native_api.h>
|
|
4
|
+
#include <js_native_api.h>
|
|
5
|
+
#include <js_native_api_types.h>
|
|
6
|
+
|
|
7
|
+
#define _check(v,errInfo) do { \
|
|
8
|
+
if (!(v)) { \
|
|
9
|
+
_isError = hpatch_TRUE; \
|
|
10
|
+
_errInfo = errInfo; \
|
|
11
|
+
goto _clear; \
|
|
12
|
+
} \
|
|
13
|
+
} while(0)
|
|
14
|
+
|
|
15
|
+
napi_value HdiffPatch(napi_env env, napi_callback_info info) {
|
|
16
|
+
napi_status status;
|
|
17
|
+
size_t argc = 2;
|
|
18
|
+
napi_value args[2];
|
|
19
|
+
hpatch_BOOL _isError = hpatch_FALSE;
|
|
20
|
+
const char* _errInfo = "";
|
|
21
|
+
|
|
22
|
+
// 获取参数
|
|
23
|
+
status = napi_get_cb_info(env, info, &argc, args, NULL, NULL);
|
|
24
|
+
if (status != napi_ok || argc < 2) {
|
|
25
|
+
napi_throw_error(env, NULL, "Wrong number of arguments");
|
|
26
|
+
return NULL;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 获取origin buffer
|
|
30
|
+
bool isTypedArray;
|
|
31
|
+
status = napi_is_typedarray(env, args[0], &isTypedArray);
|
|
32
|
+
if (status != napi_ok || !isTypedArray) {
|
|
33
|
+
napi_throw_error(env, NULL, "First argument must be a TypedArray");
|
|
34
|
+
return NULL;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
uint8_t* originPtr;
|
|
38
|
+
size_t originLength;
|
|
39
|
+
status = napi_get_typedarray_info(env, args[0], NULL, &originLength,
|
|
40
|
+
(void**)&originPtr, NULL, NULL);
|
|
41
|
+
if (status != napi_ok) {
|
|
42
|
+
napi_throw_error(env, NULL, "Failed to get origin buffer");
|
|
43
|
+
return NULL;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 获取patch buffer
|
|
47
|
+
status = napi_is_typedarray(env, args[1], &isTypedArray);
|
|
48
|
+
if (status != napi_ok || !isTypedArray) {
|
|
49
|
+
napi_throw_error(env, NULL, "Second argument must be a TypedArray");
|
|
50
|
+
return NULL;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
uint8_t* patchPtr;
|
|
54
|
+
size_t patchLength;
|
|
55
|
+
status = napi_get_typedarray_info(env, args[1], NULL, &patchLength,
|
|
56
|
+
(void**)&patchPtr, NULL, NULL);
|
|
57
|
+
if (status != napi_ok) {
|
|
58
|
+
napi_throw_error(env, NULL, "Failed to get patch buffer");
|
|
59
|
+
return NULL;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 执行patch操作
|
|
63
|
+
hpatch_singleCompressedDiffInfo patInfo;
|
|
64
|
+
|
|
65
|
+
_check(((originLength==0)||originPtr) && patchPtr && (patchLength>0), "Corrupt patch");
|
|
66
|
+
_check(kHPatch_ok==hpatch_getInfo_by_mem(&patInfo, patchPtr, patchLength), "Error info in hpatch");
|
|
67
|
+
_check(originLength==patInfo.oldDataSize, "Error oldDataSize in hpatch");
|
|
68
|
+
size_t newsize = (size_t)patInfo.newDataSize;
|
|
69
|
+
if (sizeof(size_t)!=sizeof(hpatch_StreamPos_t))
|
|
70
|
+
_check(newsize==patInfo.newDataSize, "Error newDataSize in hpatch");
|
|
71
|
+
|
|
72
|
+
// 创建结果buffer
|
|
73
|
+
napi_value resultBuffer;
|
|
74
|
+
uint8_t* outPtr;
|
|
75
|
+
void* data;
|
|
76
|
+
|
|
77
|
+
status = napi_create_arraybuffer(env, newsize, &data, &resultBuffer);
|
|
78
|
+
if (status != napi_ok) {
|
|
79
|
+
napi_throw_error(env, NULL, "Failed to create result buffer");
|
|
80
|
+
return NULL;
|
|
81
|
+
}
|
|
82
|
+
outPtr = (uint8_t*)data;
|
|
83
|
+
|
|
84
|
+
// 执行patch
|
|
85
|
+
_check(kHPatch_ok==hpatch_by_mem(originPtr, originLength, outPtr, newsize,
|
|
86
|
+
patchPtr, patchLength, &patInfo), "hpatch");
|
|
87
|
+
return resultBuffer;
|
|
88
|
+
|
|
89
|
+
_clear:
|
|
90
|
+
if (_isError) {
|
|
91
|
+
napi_throw_error(env, NULL, _errInfo);
|
|
92
|
+
return NULL;
|
|
93
|
+
}
|
|
94
|
+
return NULL;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 模块初始化
|
|
98
|
+
napi_value Init(napi_env env, napi_value exports) {
|
|
99
|
+
napi_status status;
|
|
100
|
+
napi_value fn;
|
|
101
|
+
|
|
102
|
+
status = napi_create_function(env, NULL, 0, HdiffPatch, NULL, &fn);
|
|
103
|
+
if (status != napi_ok) {
|
|
104
|
+
napi_throw_error(env, NULL, "Unable to wrap native function");
|
|
105
|
+
return NULL;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
status = napi_set_named_property(env, exports, "hdiffPatch", fn);
|
|
109
|
+
if (status != napi_ok) {
|
|
110
|
+
napi_throw_error(env, NULL, "Unable to populate exports");
|
|
111
|
+
return NULL;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return exports;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
|