sparkbun 0.1.4 → 0.1.6
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/dist-linux-arm64/libNativeWrapper.so +0 -0
- package/dist-linux-arm64/{libElectrobunCore.so → libSparkBunCore.so} +0 -0
- package/dist-linux-x64/libNativeWrapper.so +0 -0
- package/dist-linux-x64/{libElectrobunCore.so → libSparkBunCore.so} +0 -0
- package/dist-macos-arm64/libNativeWrapper.dylib +0 -0
- package/dist-macos-arm64/libSparkBunCore.dylib +0 -0
- package/dist-macos-x64/libNativeWrapper.dylib +0 -0
- package/dist-macos-x64/libSparkBunCore.dylib +0 -0
- package/dist-macos-x64/libasar.dylib +0 -0
- package/dist-macos-x64/libwebgpu_dawn.dylib +0 -0
- package/dist-macos-x64/process_helper +0 -0
- package/dist-win-arm64/SparkBunCore.dll +0 -0
- package/dist-win-arm64/WebView2Loader.dll +0 -0
- package/dist-win-arm64/libNativeWrapper.dll +0 -0
- package/dist-win-arm64/zig-asar/arm64/libasar.dll +0 -0
- package/dist-win-arm64/zig-asar/x64/libasar.dll +0 -0
- package/dist-win-x64/SparkBunCore.dll +0 -0
- package/package.json +1 -1
- package/scripts/setup-win-arm64.ps1 +19 -0
- package/src/browser/global.d.ts +11 -11
- package/src/browser/index.ts +10 -10
- package/src/bun/core/BrowserView.ts +2 -2
- package/src/bun/core/Updater.ts +6 -56
- package/src/bun/preload/.generated/compiled.ts +2 -2
- package/src/bun/preload/dragRegions.ts +2 -2
- package/src/bun/preload/encryption.ts +4 -4
- package/src/bun/preload/events.ts +4 -4
- package/src/bun/preload/globals.d.ts +14 -14
- package/src/bun/preload/index-sandboxed.ts +3 -3
- package/src/bun/preload/index.ts +19 -19
- package/src/bun/preload/internalRpc.ts +3 -3
- package/src/bun/preload/webviewTag.ts +2 -2
- package/src/bun/preload/wgpuTag.ts +1 -1
- package/src/bun/proc/native.ts +6 -6
- package/src/cli/index.ts +47 -83
- package/src/core/build.zig +1 -1
- package/src/core/main.zig +25 -24
- package/src/installer/installer-template.ts +1 -1
- package/src/launcher/main.ts +10 -10
- package/src/native/linux/cef_process_helper_linux.cpp +4 -4
- package/src/native/linux/nativeWrapper.cpp +230 -230
- package/src/native/macos/cef_process_helper_mac.cc +4 -4
- package/src/native/macos/nativeWrapper.mm +100 -100
- package/src/native/shared/accelerator_parser.h +5 -5
- package/src/native/shared/app_paths.h +7 -7
- package/src/native/shared/asar.h +5 -5
- package/src/native/shared/cache_migration.h +14 -14
- package/src/native/shared/callbacks.h +5 -5
- package/src/native/shared/cef_response_filter.h +18 -18
- package/src/native/shared/chromium_flags.h +6 -6
- package/src/native/shared/config.h +5 -5
- package/src/native/shared/download_event.h +5 -5
- package/src/native/shared/ffi_helpers.h +6 -6
- package/src/native/shared/glob_match.h +5 -5
- package/src/native/shared/json_menu_parser.h +5 -5
- package/src/native/shared/mime_types.h +5 -5
- package/src/native/shared/navigation_rules.h +5 -5
- package/src/native/shared/partition_context.h +5 -5
- package/src/native/shared/permissions.h +5 -5
- package/src/native/shared/permissions_cef.h +5 -5
- package/src/native/shared/preload_script.h +5 -5
- package/src/native/shared/shutdown_guard.h +5 -5
- package/src/native/shared/thread_safe_map.h +5 -5
- package/src/native/shared/webview_storage.h +5 -5
- package/src/native/win/cef_process_helper_win.cpp +4 -4
- package/src/native/win/dcomp_compositor.h +1 -1
- package/src/native/win/nativeWrapper.cpp +288 -288
- package/src/shared/bsdiff.ts +236 -0
- package/src/shared/bspatch.ts +98 -0
- package/dist-linux-arm64/bsdiff +0 -0
- package/dist-linux-arm64/bspatch +0 -0
- package/dist-linux-x64/bsdiff +0 -0
- package/dist-linux-x64/bspatch +0 -0
- package/dist-macos-arm64/bsdiff +0 -0
- package/dist-macos-arm64/bspatch +0 -0
- package/dist-macos-arm64/libElectrobunCore.dylib +0 -0
- package/dist-macos-arm64/preload-full.js +0 -885
- package/dist-macos-arm64/preload-sandboxed.js +0 -111
- package/dist-win-x64/ElectrobunCore.dll +0 -0
- package/dist-win-x64/bsdiff.exe +0 -0
- package/dist-win-x64/bspatch.exe +0 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// Based on bsdiff by Colin Percival (2003-2005)
|
|
2
|
+
// Zig port by Yoav Givati (2024)
|
|
3
|
+
// TypeScript port for SparkBun — uses gzip instead of zstd
|
|
4
|
+
|
|
5
|
+
const MAGIC = "SBDIFF10";
|
|
6
|
+
|
|
7
|
+
function offtin(buf: Uint8Array, offset: number): bigint {
|
|
8
|
+
let y = 0n;
|
|
9
|
+
for (let i = 0; i < 7; i++) {
|
|
10
|
+
y |= BigInt(buf[offset + i]) << BigInt(i * 8);
|
|
11
|
+
}
|
|
12
|
+
y |= BigInt(buf[offset + 7] & 0x7f) << 56n;
|
|
13
|
+
if (buf[offset + 7] & 0x80) {
|
|
14
|
+
y = -y;
|
|
15
|
+
}
|
|
16
|
+
return y;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function offtout(x: bigint, buf: Uint8Array, offset: number): void {
|
|
20
|
+
let y: bigint;
|
|
21
|
+
if (x < 0n) {
|
|
22
|
+
y = (-x) | (1n << 63n);
|
|
23
|
+
} else {
|
|
24
|
+
y = x;
|
|
25
|
+
}
|
|
26
|
+
for (let i = 0; i < 8; i++) {
|
|
27
|
+
buf[offset + i] = Number((y >> BigInt(i * 8)) & 0xffn);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function matchlen(oldData: Uint8Array, oldStart: number, newData: Uint8Array, newStart: number): number {
|
|
32
|
+
const maxLen = Math.min(oldData.length - oldStart, newData.length - newStart);
|
|
33
|
+
let i = 0;
|
|
34
|
+
while (i < maxLen && oldData[oldStart + i] === newData[newStart + i]) {
|
|
35
|
+
i++;
|
|
36
|
+
}
|
|
37
|
+
return i;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function search(
|
|
41
|
+
suffixArray: Int32Array,
|
|
42
|
+
oldData: Uint8Array,
|
|
43
|
+
newData: Uint8Array,
|
|
44
|
+
newStart: number,
|
|
45
|
+
lo: number,
|
|
46
|
+
hi: number,
|
|
47
|
+
bestPos: { value: number },
|
|
48
|
+
): number {
|
|
49
|
+
if (hi - lo < 2) {
|
|
50
|
+
const loMatch = matchlen(oldData, suffixArray[lo], newData, newStart);
|
|
51
|
+
const hiMatch = matchlen(oldData, suffixArray[hi], newData, newStart);
|
|
52
|
+
if (loMatch > hiMatch) {
|
|
53
|
+
bestPos.value = suffixArray[lo];
|
|
54
|
+
return loMatch;
|
|
55
|
+
}
|
|
56
|
+
bestPos.value = suffixArray[hi];
|
|
57
|
+
return hiMatch;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const mid = lo + ((hi - lo) >>> 1);
|
|
61
|
+
const midPos = suffixArray[mid];
|
|
62
|
+
const compareLen = Math.min(oldData.length - midPos, newData.length - newStart);
|
|
63
|
+
|
|
64
|
+
let cmp = 0;
|
|
65
|
+
for (let i = 0; i < compareLen; i++) {
|
|
66
|
+
if (oldData[midPos + i] < newData[newStart + i]) { cmp = -1; break; }
|
|
67
|
+
if (oldData[midPos + i] > newData[newStart + i]) { cmp = 1; break; }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (cmp < 0) {
|
|
71
|
+
return search(suffixArray, oldData, newData, newStart, mid, hi, bestPos);
|
|
72
|
+
}
|
|
73
|
+
return search(suffixArray, oldData, newData, newStart, lo, mid, bestPos);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function qsufsort(data: Uint8Array): Int32Array {
|
|
77
|
+
const n = data.length;
|
|
78
|
+
const sa = new Int32Array(n + 1);
|
|
79
|
+
for (let i = 0; i <= n; i++) sa[i] = i;
|
|
80
|
+
sa.sort((a, b) => {
|
|
81
|
+
const la = n - a;
|
|
82
|
+
const lb = n - b;
|
|
83
|
+
const len = la < lb ? la : lb;
|
|
84
|
+
for (let i = 0; i < len; i++) {
|
|
85
|
+
if (data[a + i] !== data[b + i]) return data[a + i] - data[b + i];
|
|
86
|
+
}
|
|
87
|
+
return la - lb;
|
|
88
|
+
});
|
|
89
|
+
return sa;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function createPatch(oldData: Uint8Array, newData: Uint8Array): Uint8Array {
|
|
93
|
+
const oldSize = oldData.length;
|
|
94
|
+
const newSize = newData.length;
|
|
95
|
+
|
|
96
|
+
const suffixArray = qsufsort(oldData);
|
|
97
|
+
|
|
98
|
+
const controlEntries: bigint[] = [];
|
|
99
|
+
const diffBytes: number[] = [];
|
|
100
|
+
const extraBytes: number[] = [];
|
|
101
|
+
|
|
102
|
+
let scan = 0;
|
|
103
|
+
let len = 0;
|
|
104
|
+
let lastScan = 0;
|
|
105
|
+
let lastPos = 0;
|
|
106
|
+
let lastOffset = 0;
|
|
107
|
+
let pos = 0;
|
|
108
|
+
const bestPos = { value: 0 };
|
|
109
|
+
|
|
110
|
+
while (scan < newSize) {
|
|
111
|
+
let oldscore = 0;
|
|
112
|
+
scan += len;
|
|
113
|
+
|
|
114
|
+
let scsc = scan;
|
|
115
|
+
while (scan < newSize) {
|
|
116
|
+
len = search(suffixArray, oldData, newData, scan, 0, oldSize, bestPos);
|
|
117
|
+
pos = bestPos.value;
|
|
118
|
+
|
|
119
|
+
while (scsc < scan + len) {
|
|
120
|
+
if (scsc + lastOffset < oldSize && oldData[scsc + lastOffset] === newData[scsc]) {
|
|
121
|
+
oldscore++;
|
|
122
|
+
}
|
|
123
|
+
scsc++;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (len === oldscore && len !== 0) break;
|
|
127
|
+
if (len > oldscore + 8) break;
|
|
128
|
+
if (scan + lastOffset < oldSize && oldData[scan + lastOffset] === newData[scan]) {
|
|
129
|
+
oldscore--;
|
|
130
|
+
}
|
|
131
|
+
scan++;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (len !== oldscore || scan >= newSize) {
|
|
135
|
+
let s = 0;
|
|
136
|
+
let sf = 0;
|
|
137
|
+
let lenf = 0;
|
|
138
|
+
|
|
139
|
+
for (let i = 0; lastScan + i < scan && lastPos + i < oldSize; i++) {
|
|
140
|
+
if (oldData[lastPos + i] === newData[lastScan + i]) s++;
|
|
141
|
+
if (s * 2 - i > sf * 2 - lenf) {
|
|
142
|
+
sf = s;
|
|
143
|
+
lenf = i + 1;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let lenb = 0;
|
|
148
|
+
if (scan < newSize) {
|
|
149
|
+
s = 0;
|
|
150
|
+
let sb = 0;
|
|
151
|
+
for (let i = 1; scan >= lastScan + i && pos >= i; i++) {
|
|
152
|
+
if (oldData[pos - i] === newData[scan - i]) s++;
|
|
153
|
+
if (s * 2 - i > sb * 2 - lenb) {
|
|
154
|
+
sb = s;
|
|
155
|
+
lenb = i;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (lastScan + lenf > scan - lenb) {
|
|
161
|
+
const overlap = (lastScan + lenf) - (scan - lenb);
|
|
162
|
+
s = 0;
|
|
163
|
+
let ss = 0;
|
|
164
|
+
let lens = 0;
|
|
165
|
+
for (let i = 0; i < overlap; i++) {
|
|
166
|
+
if (newData[lastScan + lenf - overlap + i] === oldData[lastPos + lenf - overlap + i]) s++;
|
|
167
|
+
if (newData[scan - lenb + i] === oldData[pos - lenb + i]) s--;
|
|
168
|
+
if (s > ss) {
|
|
169
|
+
ss = s;
|
|
170
|
+
lens = i + 1;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
lenf += lens - overlap;
|
|
174
|
+
lenb -= lens;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
for (let i = 0; i < lenf; i++) {
|
|
178
|
+
diffBytes.push((newData[lastScan + i] - oldData[lastPos + i] + 256) & 0xff);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const extraLen = (scan - lenb) - (lastScan + lenf);
|
|
182
|
+
for (let i = 0; i < extraLen; i++) {
|
|
183
|
+
extraBytes.push(newData[lastScan + lenf + i]);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
controlEntries.push(BigInt(lenf), BigInt(extraLen), BigInt((pos - lenb) - (lastPos + lenf)));
|
|
187
|
+
|
|
188
|
+
lastScan = scan - lenb;
|
|
189
|
+
lastPos = pos - lenb;
|
|
190
|
+
lastOffset = pos - scan;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const controlBuf = new Uint8Array(controlEntries.length * 8);
|
|
195
|
+
for (let i = 0; i < controlEntries.length; i++) {
|
|
196
|
+
offtout(controlEntries[i], controlBuf, i * 8);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const controlCompressed = Bun.gzipSync(controlBuf);
|
|
200
|
+
const diffCompressed = Bun.gzipSync(new Uint8Array(diffBytes));
|
|
201
|
+
const extraCompressed = Bun.gzipSync(new Uint8Array(extraBytes));
|
|
202
|
+
|
|
203
|
+
const patchSize = 32 + controlCompressed.length + diffCompressed.length + extraCompressed.length;
|
|
204
|
+
const patch = new Uint8Array(patchSize);
|
|
205
|
+
|
|
206
|
+
const encoder = new TextEncoder();
|
|
207
|
+
patch.set(encoder.encode(MAGIC), 0);
|
|
208
|
+
offtout(BigInt(controlCompressed.length), patch, 8);
|
|
209
|
+
offtout(BigInt(diffCompressed.length), patch, 16);
|
|
210
|
+
offtout(BigInt(newSize), patch, 24);
|
|
211
|
+
|
|
212
|
+
let offset = 32;
|
|
213
|
+
patch.set(controlCompressed, offset);
|
|
214
|
+
offset += controlCompressed.length;
|
|
215
|
+
patch.set(diffCompressed, offset);
|
|
216
|
+
offset += diffCompressed.length;
|
|
217
|
+
patch.set(extraCompressed, offset);
|
|
218
|
+
|
|
219
|
+
return patch;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (import.meta.main) {
|
|
223
|
+
const args = process.argv.slice(2);
|
|
224
|
+
if (args.length !== 3) {
|
|
225
|
+
console.error("Usage: bsdiff <oldfile> <newfile> <patchfile>");
|
|
226
|
+
process.exit(1);
|
|
227
|
+
}
|
|
228
|
+
const [oldPath, newPath, patchPath] = args;
|
|
229
|
+
const oldData = new Uint8Array(await Bun.file(oldPath).arrayBuffer());
|
|
230
|
+
const newData = new Uint8Array(await Bun.file(newPath).arrayBuffer());
|
|
231
|
+
const patch = createPatch(oldData, newData);
|
|
232
|
+
await Bun.write(patchPath, patch);
|
|
233
|
+
const patchKB = (patch.length / 1024).toFixed(2);
|
|
234
|
+
const ratio = ((patch.length / newData.length) * 100).toFixed(1);
|
|
235
|
+
console.error(`Completed - Patch: ${patchKB} KB (${ratio}% of new size)`);
|
|
236
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Based on bspatch by Colin Percival (2003-2005)
|
|
2
|
+
// Zig port by Yoav Givati (2024)
|
|
3
|
+
// TypeScript port for SparkBun — uses gzip instead of zstd
|
|
4
|
+
|
|
5
|
+
const MAGIC = "SBDIFF10";
|
|
6
|
+
|
|
7
|
+
function offtin(buf: Uint8Array, offset: number): bigint {
|
|
8
|
+
let y = 0n;
|
|
9
|
+
for (let i = 0; i < 7; i++) {
|
|
10
|
+
y |= BigInt(buf[offset + i]) << BigInt(i * 8);
|
|
11
|
+
}
|
|
12
|
+
y |= BigInt(buf[offset + 7] & 0x7f) << 56n;
|
|
13
|
+
if (buf[offset + 7] & 0x80) {
|
|
14
|
+
y = -y;
|
|
15
|
+
}
|
|
16
|
+
return y;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function applyPatch(oldData: Uint8Array, patchData: Uint8Array): Uint8Array {
|
|
20
|
+
const header = patchData.slice(0, 32);
|
|
21
|
+
const magic = new TextDecoder().decode(header.slice(0, 8));
|
|
22
|
+
if (magic !== MAGIC) {
|
|
23
|
+
throw new Error(`Invalid patch magic: ${magic} (expected ${MAGIC})`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const controlLen = Number(offtin(header, 8));
|
|
27
|
+
const diffLen = Number(offtin(header, 16));
|
|
28
|
+
const newSize = Number(offtin(header, 24));
|
|
29
|
+
|
|
30
|
+
if (controlLen < 0 || diffLen < 0 || newSize < 0) {
|
|
31
|
+
throw new Error("Corrupt patch: negative header length");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const controlStart = 32;
|
|
35
|
+
const diffStart = controlStart + controlLen;
|
|
36
|
+
const extraStart = diffStart + diffLen;
|
|
37
|
+
|
|
38
|
+
if (diffStart > patchData.length || extraStart > patchData.length) {
|
|
39
|
+
throw new Error("Corrupt patch: header lengths exceed patch size");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const controlBlock = Bun.gunzipSync(patchData.slice(controlStart, diffStart));
|
|
43
|
+
const diffBlock = Bun.gunzipSync(patchData.slice(diffStart, extraStart));
|
|
44
|
+
const extraBlock = Bun.gunzipSync(patchData.slice(extraStart));
|
|
45
|
+
|
|
46
|
+
const newData = new Uint8Array(newSize);
|
|
47
|
+
|
|
48
|
+
let controlPos = 0;
|
|
49
|
+
let diffPos = 0;
|
|
50
|
+
let extraPos = 0;
|
|
51
|
+
let oldPos = 0;
|
|
52
|
+
let newPos = 0;
|
|
53
|
+
|
|
54
|
+
while (controlPos < controlBlock.length) {
|
|
55
|
+
const readDiffBy = Number(offtin(controlBlock, controlPos));
|
|
56
|
+
controlPos += 8;
|
|
57
|
+
const readExtraBy = Number(offtin(controlBlock, controlPos));
|
|
58
|
+
controlPos += 8;
|
|
59
|
+
const seekBy = Number(offtin(controlBlock, controlPos));
|
|
60
|
+
controlPos += 8;
|
|
61
|
+
|
|
62
|
+
if (newPos + readDiffBy > newSize) {
|
|
63
|
+
throw new Error("Corrupt patch: diff would write past end of file");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (let i = 0; i < readDiffBy; i++) {
|
|
67
|
+
newData[newPos + i] = (oldData[oldPos + i] + diffBlock[diffPos + i]) & 0xff;
|
|
68
|
+
}
|
|
69
|
+
diffPos += readDiffBy;
|
|
70
|
+
newPos += readDiffBy;
|
|
71
|
+
oldPos += readDiffBy;
|
|
72
|
+
|
|
73
|
+
if (readExtraBy > 0) {
|
|
74
|
+
newData.set(extraBlock.slice(extraPos, extraPos + readExtraBy), newPos);
|
|
75
|
+
extraPos += readExtraBy;
|
|
76
|
+
newPos += readExtraBy;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
oldPos += seekBy;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return newData;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (import.meta.main) {
|
|
86
|
+
const args = process.argv.slice(2);
|
|
87
|
+
if (args.length !== 3) {
|
|
88
|
+
console.error("Usage: bspatch <oldfile> <newfile> <patchfile>");
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
const [oldPath, newPath, patchPath] = args;
|
|
92
|
+
const oldData = new Uint8Array(await Bun.file(oldPath).arrayBuffer());
|
|
93
|
+
const patchData = new Uint8Array(await Bun.file(patchPath).arrayBuffer());
|
|
94
|
+
const newData = applyPatch(oldData, patchData);
|
|
95
|
+
await Bun.write(newPath, newData);
|
|
96
|
+
const sizeMB = (newData.length / (1024 * 1024)).toFixed(2);
|
|
97
|
+
console.error(`Completed - New file: ${sizeMB} MB`);
|
|
98
|
+
}
|
package/dist-linux-arm64/bsdiff
DELETED
|
Binary file
|
package/dist-linux-arm64/bspatch
DELETED
|
Binary file
|
package/dist-linux-x64/bsdiff
DELETED
|
Binary file
|
package/dist-linux-x64/bspatch
DELETED
|
Binary file
|
package/dist-macos-arm64/bsdiff
DELETED
|
Binary file
|
package/dist-macos-arm64/bspatch
DELETED
|
Binary file
|
|
Binary file
|