@bravemobile/react-native-code-push 12.4.1 → 13.1.0-beta.0

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.
Files changed (111) hide show
  1. package/CodePush.podspec +47 -2
  2. package/README.md +118 -3
  3. package/THIRD-PARTY-NOTICES +96 -0
  4. package/android/app/build.gradle +26 -0
  5. package/android/app/proguard-rules.pro +5 -0
  6. package/android/app/src/main/cpp/CMakeLists.txt +38 -0
  7. package/android/app/src/main/cpp/binarypatch_jni.c +181 -0
  8. package/android/app/src/main/java/com/microsoft/codepush/react/BinaryPatchAttempt.java +92 -0
  9. package/android/app/src/main/java/com/microsoft/codepush/react/BinaryPatchResult.java +64 -0
  10. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +46 -11
  11. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBinaryPatch.java +293 -0
  12. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +25 -0
  13. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +79 -88
  14. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +159 -4
  15. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +13 -0
  16. package/android/app/src/main/java/com/microsoft/codepush/react/HDiffPatchNative.java +52 -0
  17. package/android/app/src/test/java/com/microsoft/codepush/react/CodePushBinaryPatchTest.java +393 -0
  18. package/android/app/src/test/java/com/microsoft/codepush/react/CodePushUpdateManagerBinaryPatchTest.java +207 -0
  19. package/android/app/src/test/java/com/microsoft/codepush/react/CodePushUpdateManagerDownloadTest.java +449 -0
  20. package/android/codepush-export.gradle +115 -0
  21. package/cli/commands/bundleCommand/bundleCodePush.ts +39 -7
  22. package/cli/commands/bundleCommand/index.ts +9 -1
  23. package/cli/commands/releaseCommand/addToReleaseHistory.ts +7 -0
  24. package/cli/commands/releaseCommand/index.test.ts +118 -0
  25. package/cli/commands/releaseCommand/index.ts +20 -2
  26. package/cli/commands/releaseCommand/release.test.ts +582 -0
  27. package/cli/commands/releaseCommand/release.ts +232 -15
  28. package/cli/dist/commands/bundleCommand/bundleCodePush.js +26 -7
  29. package/cli/dist/commands/bundleCommand/index.js +5 -1
  30. package/cli/dist/commands/releaseCommand/addToReleaseHistory.js +6 -1
  31. package/cli/dist/commands/releaseCommand/index.js +8 -1
  32. package/cli/dist/commands/releaseCommand/index.test.js +96 -0
  33. package/cli/dist/commands/releaseCommand/release.js +165 -17
  34. package/cli/dist/commands/releaseCommand/release.test.js +367 -0
  35. package/cli/dist/functions/makeBinaryPatchBundle.js +248 -0
  36. package/cli/dist/functions/makeBinaryPatchBundle.test.js +321 -0
  37. package/cli/dist/functions/makeCodePushBundle.js +4 -2
  38. package/cli/dist/functions/runHermesEmitBinaryCommand.js +98 -27
  39. package/cli/dist/functions/runHermesEmitBinaryCommand.test.js +100 -0
  40. package/cli/dist/jest.globalSetup.js +38 -0
  41. package/cli/dist/utils/binaryPatch.js +86 -0
  42. package/cli/dist/utils/binaryPatch.test.js +190 -0
  43. package/cli/functions/makeBinaryPatchBundle.test.ts +410 -0
  44. package/cli/functions/makeBinaryPatchBundle.ts +367 -0
  45. package/cli/functions/makeCodePushBundle.ts +4 -2
  46. package/cli/functions/runHermesEmitBinaryCommand.test.ts +124 -0
  47. package/cli/functions/runHermesEmitBinaryCommand.ts +112 -26
  48. package/cli/jest.globalSetup.ts +43 -0
  49. package/cli/utils/binaryPatch.test.ts +234 -0
  50. package/cli/utils/binaryPatch.ts +103 -0
  51. package/cpp/binarypatch/binarypatch_zstd_decompressor.c +187 -0
  52. package/cpp/binarypatch/binarypatch_zstd_decompressor.h +47 -0
  53. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/checksum_plugin.h +52 -0
  54. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/hpatch_mt/hpatch_mt.h +147 -0
  55. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch.c +3315 -0
  56. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch.h +268 -0
  57. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch_private.h +297 -0
  58. package/cpp/binarypatch/vendor/HDiffPatch/libHDiffPatch/HPatch/patch_types.h +434 -0
  59. package/cpp/binarypatch/vendor/zstd/common/allocations.h +55 -0
  60. package/cpp/binarypatch/vendor/zstd/common/bits.h +205 -0
  61. package/cpp/binarypatch/vendor/zstd/common/bitstream.h +454 -0
  62. package/cpp/binarypatch/vendor/zstd/common/compiler.h +464 -0
  63. package/cpp/binarypatch/vendor/zstd/common/cpu.h +249 -0
  64. package/cpp/binarypatch/vendor/zstd/common/debug.c +30 -0
  65. package/cpp/binarypatch/vendor/zstd/common/debug.h +107 -0
  66. package/cpp/binarypatch/vendor/zstd/common/entropy_common.c +340 -0
  67. package/cpp/binarypatch/vendor/zstd/common/error_private.c +64 -0
  68. package/cpp/binarypatch/vendor/zstd/common/error_private.h +158 -0
  69. package/cpp/binarypatch/vendor/zstd/common/fse.h +625 -0
  70. package/cpp/binarypatch/vendor/zstd/common/fse_decompress.c +315 -0
  71. package/cpp/binarypatch/vendor/zstd/common/huf.h +277 -0
  72. package/cpp/binarypatch/vendor/zstd/common/mem.h +422 -0
  73. package/cpp/binarypatch/vendor/zstd/common/pool.c +371 -0
  74. package/cpp/binarypatch/vendor/zstd/common/pool.h +81 -0
  75. package/cpp/binarypatch/vendor/zstd/common/portability_macros.h +171 -0
  76. package/cpp/binarypatch/vendor/zstd/common/threading.c +182 -0
  77. package/cpp/binarypatch/vendor/zstd/common/threading.h +142 -0
  78. package/cpp/binarypatch/vendor/zstd/common/xxhash.c +18 -0
  79. package/cpp/binarypatch/vendor/zstd/common/xxhash.h +7094 -0
  80. package/cpp/binarypatch/vendor/zstd/common/zstd_common.c +48 -0
  81. package/cpp/binarypatch/vendor/zstd/common/zstd_deps.h +123 -0
  82. package/cpp/binarypatch/vendor/zstd/common/zstd_internal.h +324 -0
  83. package/cpp/binarypatch/vendor/zstd/common/zstd_trace.h +156 -0
  84. package/cpp/binarypatch/vendor/zstd/decompress/huf_decompress.c +1944 -0
  85. package/cpp/binarypatch/vendor/zstd/decompress/zstd_ddict.c +244 -0
  86. package/cpp/binarypatch/vendor/zstd/decompress/zstd_ddict.h +44 -0
  87. package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress.c +2410 -0
  88. package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress_block.c +2209 -0
  89. package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress_block.h +73 -0
  90. package/cpp/binarypatch/vendor/zstd/decompress/zstd_decompress_internal.h +240 -0
  91. package/cpp/binarypatch/vendor/zstd/zstd.h +3206 -0
  92. package/cpp/binarypatch/vendor/zstd/zstd_errors.h +107 -0
  93. package/ios/CodePush/CodePush.h +58 -9
  94. package/ios/CodePush/{CodePush.m → CodePush.mm} +77 -63
  95. package/ios/CodePush/CodePushBinaryPatch.h +80 -0
  96. package/ios/CodePush/CodePushBinaryPatch.m +473 -0
  97. package/ios/CodePush/CodePushPackage.m +183 -2
  98. package/ios/CodePush/CodePushUpdateUtils.m +49 -1
  99. package/ios/CodePush.xcodeproj/project.pbxproj +6 -6
  100. package/package.json +28 -4
  101. package/react-native.config.js +3 -1
  102. package/scripts/binary-patch/build-hdiffpatch.sh +86 -0
  103. package/scripts/export-embedded-bundle.sh +76 -0
  104. package/src/CodePush.js +190 -96
  105. package/src/CodePush.test.js +382 -0
  106. package/src/native/NativeCodePush.ts +162 -0
  107. package/src/package-mixins.js +24 -11
  108. package/src/specs/NativeCodePush.ts +43 -0
  109. package/typings/react-native-code-push.d.ts +77 -0
  110. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +0 -102
  111. package/src/AlertAdapter.js +0 -24
@@ -0,0 +1,268 @@
1
+ //patch.h
2
+ //
3
+ /*
4
+ The MIT License (MIT)
5
+ Copyright (c) 2012-2018 HouSisong
6
+
7
+ Permission is hereby granted, free of charge, to any person
8
+ obtaining a copy of this software and associated documentation
9
+ files (the "Software"), to deal in the Software without
10
+ restriction, including without limitation the rights to use,
11
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the
13
+ Software is furnished to do so, subject to the following
14
+ conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26
+ OTHER DEALINGS IN THE SOFTWARE.
27
+ */
28
+
29
+ #ifndef HPatch_patch_h
30
+ #define HPatch_patch_h
31
+ #include "patch_types.h"
32
+ #include "hpatch_mt/hpatch_mt.h"
33
+ #include "checksum_plugin.h"
34
+
35
+ #ifdef __cplusplus
36
+ extern "C" {
37
+ #endif
38
+
39
+ //all patch*() functions do not allocate memory
40
+
41
+ //optimize speed for patch_stream_with_cache() & patch_decompress_with_cache()
42
+ // & patch_single_stream(),patch_single_compressed_diff(),patch_single_stream_diff():
43
+ // preload part of oldData into cache,
44
+ // cache memory size (temp_cache_end-temp_cache) the larger the better for large oldData file
45
+ #ifndef _IS_NEED_CACHE_OLD_BY_COVERS
46
+ # define _IS_NEED_CACHE_OLD_BY_COVERS 1
47
+ #endif
48
+ #ifndef _IS_NEED_CACHE_OLD_ALL
49
+ # define _IS_NEED_CACHE_OLD_ALL 1
50
+ #endif
51
+
52
+
53
+ //generate newData by patch(oldData + serializedDiff)
54
+ // serializedDiff create by create_diff()
55
+ // NOTE: create_diff() + patch() or patch_stream() or patch_stream_with_cache() is no longer recommended,
56
+ // recommend change to use create_single_compressed_diff() + patch_single_stream() or patch_single_compressed_diff()
57
+ hpatch_BOOL patch(unsigned char* out_newData,unsigned char* out_newData_end,
58
+ const unsigned char* oldData,const unsigned char* oldData_end,
59
+ const unsigned char* serializedDiff,const unsigned char* serializedDiff_end);
60
+
61
+ //patch by stream, see patch()
62
+ // used (hpatch_kStreamCacheSize*8 stack memory) for I/O cache
63
+ // if use patch_stream_with_cache(), can passing larger memory cache to optimize speed
64
+ // serializedDiff create by create_diff()
65
+ // NOTE: create_diff() + patch() or patch_stream() or patch_stream_with_cache() is no longer recommended,
66
+ // recommend change to use create_single_compressed_diff() + patch_single_stream() or patch_single_compressed_diff()
67
+ hpatch_BOOL patch_stream(const hpatch_TStreamOutput* out_newData, //sequential write
68
+ const hpatch_TStreamInput* oldData, //random read
69
+ const hpatch_TStreamInput* serializedDiff); //random read
70
+
71
+ //see patch_stream()
72
+ // can passing more memory for I/O cache to optimize speed
73
+ // note: (temp_cache_end-temp_cache)>=2048
74
+ // NOTE: create_diff() + patch() or patch_stream() or patch_stream_with_cache() is no longer recommended,
75
+ // recommend change to use create_single_compressed_diff() + patch_single_stream() or patch_single_compressed_diff()
76
+ hpatch_BOOL patch_stream_with_cache(const hpatch_TStreamOutput* out_newData, //sequential write
77
+ const hpatch_TStreamInput* oldData, //random read
78
+ const hpatch_TStreamInput* serializedDiff, //random read
79
+ unsigned char* temp_cache,unsigned char* temp_cache_end);
80
+
81
+
82
+
83
+
84
+ //get compressedDiff info
85
+ // compressedDiff created by create_compressed_diff() or create_compressed_diff_stream()
86
+ hpatch_BOOL getCompressedDiffInfo(hpatch_compressedDiffInfo* out_diffInfo,
87
+ const hpatch_TStreamInput* compressedDiff);
88
+ //see getCompressedDiffInfo()
89
+ hpatch_inline static hpatch_BOOL
90
+ getCompressedDiffInfo_mem(hpatch_compressedDiffInfo* out_diffInfo,
91
+ const unsigned char* compressedDiff,
92
+ const unsigned char* compressedDiff_end){
93
+ hpatch_TStreamInput diffStream;
94
+ mem_as_hStreamInput(&diffStream,compressedDiff,compressedDiff_end);
95
+ return getCompressedDiffInfo(out_diffInfo,&diffStream);
96
+ }
97
+
98
+ //patch with decompress plugin
99
+ // used (hpatch_kStreamCacheSize*6 stack memory) + (decompress buffer*4)
100
+ // compressedDiff create by create_compressed_diff() or create_compressed_diff_stream()
101
+ // decompressPlugin can be null when there is no compressed data in compressedDiff
102
+ // if using patch_decompress_with_cache(), a larger memory cache can be passed to optimize speed
103
+ hpatch_BOOL patch_decompress(const hpatch_TStreamOutput* out_newData, //sequential write
104
+ const hpatch_TStreamInput* oldData, //random read
105
+ const hpatch_TStreamInput* compressedDiff, //random read
106
+ hpatch_TDecompress* decompressPlugin);
107
+
108
+ //see patch_decompress()
109
+ // can passing larger memory cache to optimize speed
110
+ // note: (temp_cache_end-temp_cache)>=2048
111
+ hpatch_BOOL patch_decompress_with_cache(const hpatch_TStreamOutput* out_newData, //sequential write
112
+ const hpatch_TStreamInput* oldData, //random read
113
+ const hpatch_TStreamInput* compressedDiff, //random read
114
+ hpatch_TDecompress* decompressPlugin,
115
+ unsigned char* temp_cache,unsigned char* temp_cache_end);
116
+
117
+ //see patch_decompress()
118
+ hpatch_inline static hpatch_BOOL
119
+ patch_decompress_mem(unsigned char* out_newData,unsigned char* out_newData_end,
120
+ const unsigned char* oldData,const unsigned char* oldData_end,
121
+ const unsigned char* compressedDiff,const unsigned char* compressedDiff_end,
122
+ hpatch_TDecompress* decompressPlugin){
123
+ hpatch_TStreamOutput out_newStream;
124
+ hpatch_TStreamInput oldStream;
125
+ hpatch_TStreamInput diffStream;
126
+ mem_as_hStreamOutput(&out_newStream,out_newData,out_newData_end);
127
+ mem_as_hStreamInput(&oldStream,oldData,oldData_end);
128
+ mem_as_hStreamInput(&diffStream,compressedDiff,compressedDiff_end);
129
+ return patch_decompress(&out_newStream,&oldStream,&diffStream,decompressPlugin);
130
+ }
131
+
132
+
133
+
134
+
135
+ // hpatch_TCoverList: open diffData and read coverList
136
+ typedef struct hpatch_TCoverList{
137
+ hpatch_TCovers* ICovers;
138
+ //private:
139
+ unsigned char _buf[hpatch_kStreamCacheSize*4];
140
+ } hpatch_TCoverList;
141
+
142
+ hpatch_inline static
143
+ void hpatch_coverList_init(hpatch_TCoverList* coverList) {
144
+ assert(coverList!=0); memset(coverList,0,sizeof(*coverList)-sizeof(coverList->_buf)); }
145
+ // serializedDiff create by create_diff()
146
+ hpatch_BOOL hpatch_coverList_open_serializedDiff(hpatch_TCoverList* out_coverList,
147
+ const hpatch_TStreamInput* serializedDiff);
148
+ // compressedDiff create by create_compressed_diff() or create_compressed_diff_stream()
149
+ hpatch_BOOL hpatch_coverList_open_compressedDiff(hpatch_TCoverList* out_coverList,
150
+ const hpatch_TStreamInput* compressedDiff,
151
+ hpatch_TDecompress* decompressPlugin);
152
+ hpatch_inline static
153
+ hpatch_BOOL hpatch_coverList_close(hpatch_TCoverList* coverList) {
154
+ hpatch_BOOL result=hpatch_TRUE;
155
+ if ((coverList!=0)&&(coverList->ICovers)){
156
+ result=coverList->ICovers->close(coverList->ICovers);
157
+ hpatch_coverList_init(coverList); } return result; }
158
+
159
+
160
+ //patch singleCompressedDiff with listener
161
+ // used (stepMemSize memory) + (I/O cache memory) + (decompress buffer*1)
162
+ // every byte in singleCompressedDiff will only be read once in order
163
+ // singleCompressedDiff create by create_single_compressed_diff() or create_single_compressed_diff_stream() or create_hdiff_by_sign()
164
+ // you can download&patch diffData at the same time, without saving it to disk
165
+ // same as calling getSingleCompressedDiffInfo() + listener->onDiffInfo() + patch_single_compressed_diff()
166
+ static hpatch_force_inline
167
+ hpatch_BOOL patch_single_stream(sspatch_listener_t* listener, //call back when got diffInfo
168
+ const hpatch_TStreamOutput* out_newData, //sequential write
169
+ const hpatch_TStreamInput* oldData, //random read
170
+ const hpatch_TStreamInput* singleCompressedDiff, //sequential read every byte
171
+ hpatch_StreamPos_t diffInfo_pos, //default 0, begin pos in singleCompressedDiff
172
+ sspatch_coversListener_t* coversListener, //default NULL, call by on got some covers
173
+ size_t threadNum){ // 1..5; if >1, multi-thread for I/O & decompress etc.
174
+ return _patch_single_stream_mt(listener,out_newData,oldData,singleCompressedDiff,
175
+ diffInfo_pos,coversListener,threadNum,hpatchMTSets_full);
176
+ }
177
+ static hpatch_force_inline
178
+ hpatch_BOOL patch_single_stream_mem(sspatch_listener_t* listener,
179
+ unsigned char* out_newData,unsigned char* out_newData_end,
180
+ const unsigned char* oldData,const unsigned char* oldData_end,
181
+ const unsigned char* diff,const unsigned char* diff_end,
182
+ sspatch_coversListener_t* coversListener,size_t threadNum){
183
+ hpatch_TStreamOutput out_newStream;
184
+ hpatch_TStreamInput oldStream;
185
+ hpatch_TStreamInput diffStream;
186
+ const hpatchMTSets_t hpatchMTSets={0,0,0,1}; //all data in mem, I/O not need MT
187
+ mem_as_hStreamOutput(&out_newStream,out_newData,out_newData_end);
188
+ mem_as_hStreamInput(&oldStream,oldData,oldData_end);
189
+ mem_as_hStreamInput(&diffStream,diff,diff_end);
190
+ return _patch_single_stream_mt(listener,&out_newStream,&oldStream,&diffStream,0,coversListener,
191
+ threadNum,hpatchMTSets);
192
+ }
193
+
194
+ //get singleCompressedDiff info
195
+ // singleCompressedDiff create by create_single_compressed_diff() or create_single_compressed_diff_stream() or create_hdiff_by_sign()
196
+ hpatch_BOOL getSingleCompressedDiffInfo(hpatch_singleCompressedDiffInfo* out_diffInfo,
197
+ const hpatch_TStreamInput* singleCompressedDiff, //sequential read
198
+ hpatch_StreamPos_t diffInfo_pos//default 0, begin pos in singleCompressedDiff
199
+ );
200
+ static hpatch_force_inline
201
+ hpatch_BOOL getSingleCompressedDiffInfo_mem(hpatch_singleCompressedDiffInfo* out_diffInfo,
202
+ const unsigned char* singleCompressedDiff,
203
+ const unsigned char* singleCompressedDiff_end){
204
+ hpatch_TStreamInput diffStream;
205
+ mem_as_hStreamInput(&diffStream,singleCompressedDiff,singleCompressedDiff_end);
206
+ return getSingleCompressedDiffInfo(out_diffInfo,&diffStream,0);
207
+ }
208
+
209
+
210
+ //patch singleCompressedDiff with diffInfo
211
+ // used (stepMemSize memory) + (I/O cache memory) + (decompress buffer*1)
212
+ // note: (I/O cache memory) >= hpatch_kStreamCacheSize*3
213
+ // temp_cache_end-temp_cache == stepMemSize + (I/O cache memory)
214
+ // singleCompressedDiff create by create_single_compressed_diff() or create_single_compressed_diff_stream() or create_hdiff_by_sign()
215
+ // decompressPlugin can be null when there is no compressed data in singleCompressedDiff
216
+ // same as calling compressed_stream_as_uncompressed() + patch_single_stream_diff()
217
+ static hpatch_force_inline
218
+ hpatch_BOOL patch_single_compressed_diff(const hpatch_TStreamOutput* out_newData, //sequential write
219
+ const hpatch_TStreamInput* oldData, //random read
220
+ const hpatch_TStreamInput* singleCompressedDiff, //sequential read
221
+ hpatch_StreamPos_t diffData_pos, //diffData begin pos in singleCompressedDiff
222
+ hpatch_StreamPos_t uncompressedSize,
223
+ hpatch_StreamPos_t compressedSize,
224
+ hpatch_TDecompress* decompressPlugin,
225
+ hpatch_StreamPos_t coverCount,hpatch_size_t stepMemSize,
226
+ unsigned char* temp_cache,unsigned char* temp_cache_end,
227
+ sspatch_coversListener_t* coversListener, //default NULL, call by on got covers
228
+ size_t threadNum){ // 1..5; if >1, multi-thread for I/O & decompress etc.
229
+ return _patch_single_compressed_diff_mt(out_newData,oldData,singleCompressedDiff,diffData_pos,uncompressedSize,compressedSize,
230
+ decompressPlugin,coverCount,stepMemSize,temp_cache,temp_cache_end,coversListener,
231
+ threadNum,hpatchMTSets_full);
232
+ }
233
+
234
+ hpatch_BOOL compressed_stream_as_uncompressed(hpatch_TUncompresser_t* uncompressedStream,hpatch_StreamPos_t uncompressedSize,
235
+ hpatch_TDecompress* decompressPlugin,const hpatch_TStreamInput* compressedStream,
236
+ hpatch_StreamPos_t compressed_pos,hpatch_StreamPos_t compressed_end);
237
+ void close_compressed_stream_as_uncompressed(hpatch_TUncompresser_t* uncompressedStream);
238
+
239
+ hpatch_BOOL patch_single_stream_diff(const hpatch_TStreamOutput* out_newData, //sequential write
240
+ const hpatch_TStreamInput* oldData, //random read
241
+ const hpatch_TStreamInput* uncompressedDiffData, //sequential read
242
+ hpatch_StreamPos_t diffData_pos,//diffData begin pos in uncompressedDiffData
243
+ hpatch_StreamPos_t diffData_posEnd,//diffData end pos in uncompressedDiffData
244
+ hpatch_StreamPos_t coverCount,hpatch_size_t stepMemSize,
245
+ unsigned char* temp_cache,unsigned char* temp_cache_end,
246
+ sspatch_coversListener_t* coversListener,
247
+ hpatch_BOOL isNeedOutCache //default true: each time accumulating some data be write to out_newData;
248
+ );
249
+
250
+
251
+ hpatch_BOOL getWindowDiffInfo(hpatch_windowDiffInfo* out_diffInfo,
252
+ const hpatch_TStreamInput* windowDiff, //sequential read
253
+ hpatch_StreamPos_t diffInfo_pos//default 0, begin pos in windowDiff
254
+ );
255
+
256
+ TWindowPatchResult patch_window_diff(struct winpatch_listener_t* listener,
257
+ const hpatch_TStreamOutput* out_newData, //sequential write
258
+ const hpatch_TStreamInput* oldData, //random read
259
+ const hpatch_TStreamInput* windowDiff, //sequential read
260
+ hpatch_StreamPos_t diffInfo_pos, //default 0, begin pos in windowDiff
261
+ size_t threadNum //1 for single-threaded, 2..5 for MT I/O
262
+ );
263
+
264
+ #ifdef __cplusplus
265
+ }
266
+ #endif
267
+
268
+ #endif
@@ -0,0 +1,297 @@
1
+ // patch_private.h
2
+ //
3
+ /*
4
+ The MIT License (MIT)
5
+ Copyright (c) 2012-2018 HouSisong
6
+
7
+ Permission is hereby granted, free of charge, to any person
8
+ obtaining a copy of this software and associated documentation
9
+ files (the "Software"), to deal in the Software without
10
+ restriction, including without limitation the rights to use,
11
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the
13
+ Software is furnished to do so, subject to the following
14
+ conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26
+ OTHER DEALINGS IN THE SOFTWARE.
27
+ */
28
+
29
+ #ifndef HPatch_patch_private_h
30
+ #define HPatch_patch_private_h
31
+
32
+ #include "patch.h"
33
+
34
+ #ifdef __cplusplus
35
+ extern "C" {
36
+ #endif
37
+
38
+
39
+ //byte rle type , ctrl code: high 2bit + packedLen(6bit+...)
40
+ typedef enum TByteRleType{
41
+ kByteRleType_rle0 = 0, //00 rle 0 , data code:0 byte
42
+ kByteRleType_rle255= 1, //01 rle 255, data code:0 byte
43
+ kByteRleType_rle = 2, //10 rle x(1--254), data code:1 byte (save x)
44
+ kByteRleType_unrle = 3 //11 n byte data, data code:n byte(save no rle data)
45
+ } TByteRleType;
46
+
47
+ static const hpatch_uint kByteRleType_bit=2;
48
+
49
+
50
+ typedef struct _THDiffzHead{
51
+ hpatch_StreamPos_t coverCount;
52
+
53
+ hpatch_StreamPos_t cover_buf_size;
54
+ hpatch_StreamPos_t compress_cover_buf_size;
55
+ hpatch_StreamPos_t rle_ctrlBuf_size;
56
+ hpatch_StreamPos_t compress_rle_ctrlBuf_size;
57
+ hpatch_StreamPos_t rle_codeBuf_size;
58
+ hpatch_StreamPos_t compress_rle_codeBuf_size;
59
+ hpatch_StreamPos_t newDataDiff_size;
60
+ hpatch_StreamPos_t compress_newDataDiff_size;
61
+
62
+ hpatch_StreamPos_t typesEndPos;
63
+ hpatch_StreamPos_t compressSizeBeginPos;
64
+ hpatch_StreamPos_t headEndPos;
65
+ hpatch_StreamPos_t coverEndPos;
66
+ } _THDiffzHead;
67
+
68
+ hpatch_BOOL read_diffz_head(hpatch_compressedDiffInfo* out_diffInfo,_THDiffzHead* out_head,
69
+ const hpatch_TStreamInput* compressedDiff);
70
+
71
+ // Stream Clip cache
72
+ typedef struct TStreamCacheClip{
73
+ hpatch_StreamPos_t streamPos;
74
+ hpatch_StreamPos_t streamPos_end;
75
+ const hpatch_TStreamInput* srcStream;
76
+ unsigned char* cacheBuf;
77
+ hpatch_size_t cacheBegin;
78
+ hpatch_size_t cacheEnd;
79
+ } TStreamCacheClip;
80
+
81
+ hpatch_inline static
82
+ void _TStreamCacheClip_init(TStreamCacheClip* sclip,const hpatch_TStreamInput* srcStream,
83
+ hpatch_StreamPos_t streamPos,hpatch_StreamPos_t streamPos_end,
84
+ unsigned char* aCache,hpatch_size_t cacheSize){
85
+ assert((streamPos<=streamPos_end)&&(streamPos_end<=(srcStream?srcStream->streamSize:0)));
86
+ sclip->streamPos=streamPos;
87
+ sclip->streamPos_end=streamPos_end;
88
+ sclip->srcStream=srcStream;
89
+ sclip->cacheBuf=aCache;
90
+ sclip->cacheBegin=cacheSize;
91
+ sclip->cacheEnd=cacheSize;
92
+ }
93
+
94
+ #define _TStreamCacheClip_isFinish(sclip) ( 0==_TStreamCacheClip_leaveSize(sclip) )
95
+ #define _TStreamCacheClip_isCacheEmpty(sclip) ( (sclip)->cacheBegin==(sclip)->cacheEnd )
96
+ #define _TStreamCacheClip_cachedSize(sclip) ( (hpatch_size_t)((sclip)->cacheEnd-(sclip)->cacheBegin) )
97
+ #define _TStreamCacheClip_leaveSize(sclip) \
98
+ ( (hpatch_StreamPos_t)((sclip)->streamPos_end-(sclip)->streamPos) \
99
+ + (hpatch_StreamPos_t)_TStreamCacheClip_cachedSize(sclip) )
100
+ #define _TStreamCacheClip_readPosOfSrcStream(sclip) ( \
101
+ (sclip)->streamPos - _TStreamCacheClip_cachedSize(sclip) )
102
+
103
+ hpatch_BOOL _TStreamCacheClip_updateCache(TStreamCacheClip* sclip);
104
+
105
+ hpatch_inline static //error return 0
106
+ unsigned char* _TStreamCacheClip_accessData(TStreamCacheClip* sclip,hpatch_size_t readSize){
107
+ //assert(readSize<=sclip->cacheEnd);
108
+ if (readSize>_TStreamCacheClip_cachedSize(sclip)){
109
+ if (!_TStreamCacheClip_updateCache(sclip)) return 0;
110
+ if (readSize>_TStreamCacheClip_cachedSize(sclip)) return 0;
111
+ }
112
+ return &sclip->cacheBuf[sclip->cacheBegin];
113
+ }
114
+
115
+ #define _TStreamCacheClip_skipData_noCheck(sclip,skipSize) ((sclip)->cacheBegin+=skipSize)
116
+ hpatch_BOOL _TStreamCacheClip_skipData(TStreamCacheClip* sclip,hpatch_StreamPos_t skipLongSize);
117
+
118
+ hpatch_inline static //error return 0
119
+ unsigned char* _TStreamCacheClip_readData(TStreamCacheClip* sclip,hpatch_size_t readSize){
120
+ unsigned char* result=_TStreamCacheClip_accessData(sclip,readSize);
121
+ _TStreamCacheClip_skipData_noCheck(sclip,readSize);
122
+ return result;
123
+ }
124
+
125
+ hpatch_BOOL _TStreamCacheClip_readDataTo(TStreamCacheClip* sclip,
126
+ unsigned char* out_buf,unsigned char* bufEnd);
127
+ hpatch_BOOL _TStreamCacheClip_addDataTo(TStreamCacheClip* self,unsigned char* dst,hpatch_size_t addLen);
128
+
129
+ hpatch_BOOL _TStreamCacheClip_unpackUIntWithTag(TStreamCacheClip* sclip,
130
+ hpatch_StreamPos_t* result,const hpatch_uint kTagBit);
131
+
132
+ hpatch_BOOL _TStreamCacheClip_readStr_end(TStreamCacheClip* sclip,hpatch_byte endTag,
133
+ char* out_str,size_t strBufLen);
134
+ hpatch_inline static
135
+ hpatch_BOOL _TStreamCacheClip_readType_end(TStreamCacheClip* sclip,hpatch_byte endTag,
136
+ char out_type[hpatch_kMaxPluginTypeLength+1]){
137
+ return _TStreamCacheClip_readStr_end(sclip,endTag,out_type,hpatch_kMaxPluginTypeLength+1); }
138
+
139
+ // Stream Clip cache
140
+ typedef struct {
141
+ hpatch_StreamPos_t writeToPos;
142
+ const hpatch_TStreamOutput* dstStream;
143
+ unsigned char* cacheBuf;
144
+ hpatch_size_t cacheCur;
145
+ hpatch_size_t cacheEnd;
146
+ } _TOutStreamCache;
147
+
148
+ static hpatch_inline void _TOutStreamCache_init(_TOutStreamCache* self,const hpatch_TStreamOutput* dstStream,
149
+ unsigned char* aCache,hpatch_size_t aCacheSize){
150
+ self->writeToPos=0;
151
+ self->cacheCur=0;
152
+ self->dstStream=dstStream;
153
+ self->cacheBuf=aCache;
154
+ self->cacheEnd=aCacheSize;
155
+ }
156
+ hpatch_inline static
157
+ void _TOutStreamCache_resetCache(_TOutStreamCache* self,unsigned char* aCache,hpatch_size_t aCacheSize){
158
+ assert(0==self->cacheCur);
159
+ self->cacheBuf=aCache;
160
+ self->cacheEnd=aCacheSize;
161
+ }
162
+
163
+ static hpatch_inline hpatch_StreamPos_t _TOutStreamCache_leaveSize(const _TOutStreamCache* self){
164
+ return self->dstStream->streamSize-self->writeToPos;
165
+ }
166
+ static hpatch_inline hpatch_BOOL _TOutStreamCache_isFinish(const _TOutStreamCache* self){
167
+ return self->writeToPos==self->dstStream->streamSize;
168
+ }
169
+ static hpatch_inline hpatch_size_t _TOutStreamCache_cachedDataSize(const _TOutStreamCache* self){
170
+ return self->cacheCur;
171
+ }
172
+ hpatch_BOOL _TOutStreamCache_flush(_TOutStreamCache* self);
173
+ hpatch_BOOL _TOutStreamCache_write(_TOutStreamCache* self,const unsigned char* data,hpatch_size_t dataSize);
174
+ hpatch_BOOL _TOutStreamCache_fill(_TOutStreamCache* self,hpatch_byte fillValue,hpatch_StreamPos_t fillLength);
175
+
176
+ hpatch_BOOL _TOutStreamCache_copyFromClip(_TOutStreamCache* self,TStreamCacheClip* src,hpatch_StreamPos_t copyLength);
177
+ hpatch_BOOL _TOutStreamCache_copyFromStream(_TOutStreamCache* self,const hpatch_TStreamInput* src,
178
+ hpatch_StreamPos_t srcPos,hpatch_StreamPos_t copyLength);
179
+ hpatch_BOOL _TOutStreamCache_copyFromSelf(_TOutStreamCache* self,hpatch_StreamPos_t aheadLength,hpatch_StreamPos_t copyLength);
180
+
181
+
182
+ typedef struct _TDecompressInputStream{
183
+ hpatch_TStreamInput IInputStream;
184
+ hpatch_TDecompress* decompressPlugin;
185
+ hpatch_decompressHandle decompressHandle;
186
+ } _TDecompressInputStream;
187
+
188
+ hpatch_BOOL getStreamClip(TStreamCacheClip* out_clip,_TDecompressInputStream* out_stream,
189
+ hpatch_StreamPos_t dataSize,hpatch_StreamPos_t compressedSize,
190
+ const hpatch_TStreamInput* stream,hpatch_StreamPos_t* pCurStreamPos,
191
+ hpatch_TDecompress* decompressPlugin,unsigned char* aCache,hpatch_size_t cacheSize);
192
+
193
+
194
+ #define _TDiffToSingleStream_kBufSize hpatch_kStreamCacheSize
195
+ typedef struct {
196
+ hpatch_TStreamInput base;
197
+ const hpatch_TStreamInput* diffStream;
198
+ hpatch_StreamPos_t readedSize;
199
+ hpatch_size_t cachedBufBegin;
200
+ hpatch_BOOL isInSingleStream;
201
+ unsigned char buf[_TDiffToSingleStream_kBufSize];
202
+ } TDiffToSingleStream;
203
+
204
+ void TDiffToSingleStream_init(TDiffToSingleStream* self,const hpatch_TStreamInput* diffStream);
205
+ hpatch_inline static
206
+ void TDiffToSingleStream_setInSingleStream(TDiffToSingleStream* self,hpatch_StreamPos_t singleStreamPos){
207
+ self->isInSingleStream=hpatch_TRUE; }
208
+
209
+ hpatch_inline static
210
+ void TDiffToSingleStream_resetStream(TDiffToSingleStream* self,const hpatch_TStreamInput* diffStream){
211
+ self->diffStream=diffStream; }
212
+
213
+ static hpatch_force_inline
214
+ hpatch_StreamPos_t _patch_cache_all_old_needSize(hpatch_StreamPos_t oldDataSize,hpatch_size_t kMinTempCacheSize){
215
+ return oldDataSize+kMinTempCacheSize+sizeof(hpatch_TStreamInput)+sizeof(hpatch_StreamPos_t); }
216
+ #if (_IS_NEED_CACHE_OLD_ALL)
217
+ static hpatch_force_inline
218
+ hpatch_BOOL _patch_is_can_cache_all_old(hpatch_StreamPos_t oldDataSize,hpatch_size_t kMinTempCacheSize,hpatch_size_t tempCacheSize){
219
+ return tempCacheSize>=_patch_cache_all_old_needSize(oldDataSize,kMinTempCacheSize); }
220
+ hpatch_BOOL _patch_cache_all_old(const hpatch_TStreamInput** poldData,size_t kMinTempCacheSize,
221
+ hpatch_byte** ptemp_cache,hpatch_byte** ptemp_cache_end,hpatch_BOOL* out_isReadError);// try cache all oldData
222
+ #else
223
+ static hpatch_force_inline
224
+ hpatch_BOOL _patch_is_can_cache_all_old(hpatch_StreamPos_t oldDataSize,hpatch_size_t kMinTempCacheSize,hpatch_size_t tempCacheSize){
225
+ return hpatch_FALSE; }
226
+ static hpatch_force_inline
227
+ hpatch_BOOL _patch_cache_all_old(const hpatch_TStreamInput** poldData,size_t kMinTempCacheSize,
228
+ hpatch_byte** ptemp_cache,hpatch_byte** ptemp_cache_end,hpatch_BOOL* out_isReadError){
229
+ *out_isReadError=hpatch_FALSE; return hpatch_FALSE; }
230
+ #endif
231
+
232
+ #if (_IS_NEED_CACHE_OLD_BY_COVERS)
233
+
234
+ hpatch_size_t _patch_step_cache_old_canUsedSize(hpatch_size_t stepCoversMemSize,hpatch_size_t kMinTempCacheSize,hpatch_size_t tempCacheSize);
235
+
236
+ // try cache part of oldData, used by patch_single_stream_diff()
237
+ hpatch_BOOL _patch_step_cache_old(const hpatch_TStreamInput** poldData,hpatch_StreamPos_t newDataSize,size_t stepCoversMemSize,
238
+ size_t kMinTempCacheSize,hpatch_byte** ptemp_cache,hpatch_byte** ptemp_cache_end);
239
+ hpatch_BOOL _patch_step_cache_old_onStepCovers(const hpatch_TStreamInput* self,const unsigned char* covers_cache,const unsigned char* covers_cacheEnd);
240
+ #endif // _IS_NEED_CACHE_OLD_BY_COVERS
241
+ hpatch_size_t _patch_is_can_cache_window_old_canUsedSize(hpatch_size_t windowOldBufSize,hpatch_size_t stepCoversMemSize,
242
+ hpatch_size_t kMinTempCacheSize,hpatch_size_t tempCacheSize,hpatch_StreamPos_t oldDataSize);
243
+
244
+ // ---- window overlap computation (shared by ST and MT) ----
245
+
246
+ typedef struct _oldwin_info_t{
247
+ hpatch_StreamPos_t oldPos;
248
+ hpatch_StreamPos_t len;
249
+ } _oldwin_info_t;
250
+
251
+ typedef enum {
252
+ _kOverlapType_none = 0, // no overlap (or no reuse)
253
+ _kOverlapType_contained, // curr window fully contained in prev window
254
+ _kOverlapType_rightTail, // curr starts inside prev, extends past prev end (tail overlap)
255
+ _kOverlapType_leftHead, // curr starts before prev, ends inside prev (head overlap)
256
+ _kOverlapType_superset // curr fully contains prev
257
+ } _kOverlapType_t;
258
+
259
+ static hpatch_inline _kOverlapType_t _compute_window_overlap(hpatch_StreamPos_t prevOldPos, hpatch_StreamPos_t prevOldEnd,
260
+ hpatch_StreamPos_t currOldPos, hpatch_StreamPos_t currOldEnd,hpatch_StreamPos_t* out_reuseLen,
261
+ hpatch_StreamPos_t* out_reuseOff,hpatch_StreamPos_t* out_noOverlapLeft){
262
+ hpatch_StreamPos_t oStart=(prevOldPos>currOldPos)?prevOldPos:currOldPos;
263
+ hpatch_StreamPos_t oEnd=(prevOldEnd<currOldEnd)?prevOldEnd:currOldEnd;
264
+ assert((prevOldPos<=prevOldEnd)&&(currOldPos<=currOldEnd));
265
+ if (oStart>=oEnd){
266
+ *out_reuseLen=0;
267
+ *out_reuseOff=0; // no value
268
+ *out_noOverlapLeft=0; // no value
269
+ return _kOverlapType_none; // no overlap
270
+ }else if ((currOldPos>=prevOldPos)&&(currOldEnd<=prevOldEnd)){// curr include prev (fully contained)
271
+ *out_reuseLen=currOldEnd-currOldPos;
272
+ *out_reuseOff=currOldPos-prevOldPos;
273
+ *out_noOverlapLeft=0;
274
+ return _kOverlapType_contained;
275
+ }else if ((currOldPos>=prevOldPos)&&(currOldPos<prevOldEnd)){// right-side/tail overlap
276
+ *out_reuseLen=prevOldEnd-currOldPos;
277
+ *out_reuseOff=currOldPos-prevOldPos;
278
+ *out_noOverlapLeft=0;
279
+ return _kOverlapType_rightTail;
280
+ }else if ((currOldEnd>prevOldPos)&&(currOldEnd<=prevOldEnd)){// left-side/head overlap
281
+ *out_reuseLen=currOldEnd-prevOldPos;
282
+ *out_reuseOff=0;
283
+ *out_noOverlapLeft=prevOldPos-currOldPos;
284
+ return _kOverlapType_leftHead;
285
+ }else{// curr contains prev (superset)
286
+ assert((currOldPos<prevOldPos)&&(currOldEnd>prevOldEnd));
287
+ *out_reuseLen=prevOldEnd-prevOldPos;
288
+ *out_reuseOff=0;
289
+ *out_noOverlapLeft=prevOldPos-currOldPos;
290
+ return _kOverlapType_superset;
291
+ }
292
+ }
293
+
294
+ #ifdef __cplusplus
295
+ }
296
+ #endif
297
+ #endif