Skip to content

Commit 2b982ef

Browse files
sunnylqmclaude
andcommitted
Add diffWithCovers and patchSingleStream native APIs
- diffWithCovers(old, new, covers, options): create standard hdiffpatch payloads from caller-provided cover lines, with replace/merge/ native-coalesce modes and optional debugCovers introspection - patchSingleStream: file-level apply for single-compressed diffs produced by diff()/diffWithCovers() - Point HDiffPatch submodule at reactnativecn fork (over https) for the cover-listener capacity change; migrate module registration out of the namespace and guard diff-declared sizes against size_t truncation Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 6ee6c4c commit 2b982ef

8 files changed

Lines changed: 745 additions & 16 deletions

File tree

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "HDiffPatch"]
22
path = HDiffPatch
3-
url = https://github.com/sisong/HDiffPatch.git
3+
url = https://github.com/reactnativecn/HDiffPatch.git
44
[submodule "lzma"]
55
path = lzma
66
url = https://github.com/sisong/lzma.git

HDiffPatch

index.d.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,35 @@ export type BinaryLike = Buffer | ArrayBufferView;
44

55
export type DiffCallback = (err: Error | null, result?: Buffer) => void;
66
export type StreamCallback = (err: Error | null, outPath?: string) => void;
7+
export type HpatchCover = {
8+
oldPos: number | string | bigint;
9+
newPos: number | string | bigint;
10+
len: number | string | bigint;
11+
};
12+
export type DiffWithCoversResult = {
13+
diff: Buffer;
14+
usedCovers: boolean;
15+
requestedCoverCount: number;
16+
nativeCoverCapacity: number;
17+
finalCoverCount: number;
18+
coverMode: 'replace' | 'merge' | 'native-coalesce';
19+
nativeCovers?: HpatchCover[];
20+
finalCovers?: HpatchCover[];
21+
};
22+
export type DiffWithCoversOptions = {
23+
mode?: 'replace' | 'merge' | 'native-coalesce' | 'native_coalesce';
24+
debugCovers?: boolean;
25+
};
726

827
export interface NativeAddon {
928
diff(oldBuf: BinaryLike, newBuf: BinaryLike): Buffer;
1029
diff(oldBuf: BinaryLike, newBuf: BinaryLike, cb: DiffCallback): void;
30+
diffWithCovers(
31+
oldBuf: BinaryLike,
32+
newBuf: BinaryLike,
33+
covers: HpatchCover[],
34+
options?: DiffWithCoversOptions
35+
): DiffWithCoversResult;
1136
patch(oldBuf: BinaryLike, diffBuf: BinaryLike): Buffer;
1237
patch(oldBuf: BinaryLike, diffBuf: BinaryLike, cb: DiffCallback): void;
1338
diffStream(oldPath: string, newPath: string, outDiffPath: string): string;
@@ -24,6 +49,13 @@ export interface NativeAddon {
2449
outNewPath: string,
2550
cb: StreamCallback
2651
): void;
52+
patchSingleStream(oldPath: string, diffPath: string, outNewPath: string): string;
53+
patchSingleStream(
54+
oldPath: string,
55+
diffPath: string,
56+
outNewPath: string,
57+
cb: StreamCallback
58+
): void;
2759
}
2860

2961
export const native: NativeAddon;
@@ -34,6 +66,12 @@ export function diff(
3466
newBuf: BinaryLike,
3567
cb: DiffCallback
3668
): void;
69+
export function diffWithCovers(
70+
oldBuf: BinaryLike,
71+
newBuf: BinaryLike,
72+
covers: HpatchCover[],
73+
options?: DiffWithCoversOptions
74+
): DiffWithCoversResult;
3775

3876
export function patch(oldBuf: BinaryLike, diffBuf: BinaryLike): Buffer;
3977
export function patch(
@@ -65,13 +103,26 @@ export function patchStream(
65103
outNewPath: string,
66104
cb: StreamCallback
67105
): void;
106+
export function patchSingleStream(
107+
oldPath: string,
108+
diffPath: string,
109+
outNewPath: string
110+
): string;
111+
export function patchSingleStream(
112+
oldPath: string,
113+
diffPath: string,
114+
outNewPath: string,
115+
cb: StreamCallback
116+
): void;
68117

69118
declare const hdiffpatch: {
70119
native: NativeAddon;
71120
diff: typeof diff;
121+
diffWithCovers: typeof diffWithCovers;
72122
patch: typeof patch;
73123
diffStream: typeof diffStream;
74124
patchStream: typeof patchStream;
125+
patchSingleStream: typeof patchSingleStream;
75126
};
76127

77128
export default hdiffpatch;

0 commit comments

Comments
 (0)