@@ -7,15 +7,26 @@ Patch compatible with HDiffPatch -SD
77## Installation
88
99``` bash
10+ npm install node-hdiffpatch
11+ # or
1012bun add node-hdiffpatch
1113```
1214
13- ## Prebuilds
15+ Prebuilt binaries are bundled for: ` darwin-arm64 ` , ` darwin-x64 ` , ` linux-x64 ` ,
16+ ` linux-arm64 ` (glibc), and ` win32-x64 ` . Other platforms are not supported by
17+ the published package.
1418
15- Prebuilds are generated per target platform/arch. Build them on each target OS:
19+ ## Development
20+
21+ Clone with submodules, then build and test:
1622
1723``` bash
18- bun run prebuild
24+ git clone --recursive https://github.com/reactnativecn/node-hdiffpatch.git
25+ cd node-hdiffpatch
26+ bun install --ignore-scripts
27+ bun run prebuild # builds prebuilds/<platform>-<arch>/ for the current machine
28+ bun run test # run tests under Node
29+ bun run test:bun # run the same tests under the Bun runtime
1930```
2031
2132## Usage
@@ -24,6 +35,60 @@ bun run prebuild
2435
2536Compare two buffers and return a new hdiffpatch patch as return value.
2637
38+ ### diffWithCovers(originBuf, newBuf, covers[ , options] )
39+
40+ Create a standard hdiffpatch patch while using caller-provided cover lines when
41+ possible. By default, the supplied covers replace HDiffPatch's internal cover
42+ selection.
43+
44+ Each cover is ` { oldPos, newPos, len } ` . Values may be numbers, decimal strings,
45+ or bigint values. The returned object is:
46+
47+ ``` js
48+ {
49+ diff: Buffer,
50+ usedCovers: boolean,
51+ requestedCoverCount: number,
52+ nativeCoverCapacity: number,
53+ finalCoverCount: number,
54+ coverMode: ' replace' | ' merge' | ' native-coalesce' ,
55+ nativeCovers?: HpatchCover[],
56+ finalCovers?: HpatchCover[]
57+ }
58+ ```
59+
60+ The ` diff ` buffer is still a normal hdiffpatch payload and can be applied with
61+ ` patch(originBuf, diff) ` or an HDiffPatch-compatible apply side.
62+
63+ Set ` options.mode ` to ` merge ` to keep HDiffPatch's native covers and only add
64+ caller covers in new-file ranges not already covered by native covers:
65+
66+ ``` js
67+ const merged = hdiff .diffWithCovers (oldBuf, newBuf, covers, { mode: ' merge' });
68+ ```
69+
70+ Set ` options.mode ` to ` native-coalesce ` to keep HDiffPatch's native cover
71+ selection but coalesce adjacent native covers that have the same old/new offset
72+ delta across small gaps. This remains a standard hdiffpatch payload and is useful
73+ as a costed post-processing experiment:
74+
75+ ``` js
76+ const coalesced = hdiff .diffWithCovers (oldBuf, newBuf, [], {
77+ mode: ' native-coalesce' ,
78+ });
79+ ```
80+
81+ Set ` options.debugCovers ` to ` true ` to include the native HDiffPatch cover list
82+ and the final listener cover list in the return value. This is for diagnostics;
83+ the default return shape avoids copying cover arrays.
84+
85+ ### patchSingleStream(oldPath, diffPath, outNewPath[ , cb] )
86+
87+ Apply a single-compressed hpatch payload created by ` diff ` or ` diffWithCovers `
88+ from files. This is the file-level apply path for the normal in-memory ` diff `
89+ format. In sync mode returns ` outNewPath ` . In async mode, callback signature is
90+ ` (err, outNewPath) ` .
91+
2792### diffStream(oldPath, newPath, outDiffPath[ , cb] )
2893
2994Create diff file by streaming file paths (low memory). In sync mode returns
@@ -43,3 +108,13 @@ After install, you can run:
43108hdp diff < oldFile> < newFile> < outDiff>
44109hdp patch < oldFile> < diffFile> < outNew>
45110```
111+
112+ Note: ` hdp patch ` auto-detects the diff format by its header, so it can apply
113+ both streaming diffs created by ` hdp diff ` and single-compressed diffs created
114+ by the in-memory ` diff() ` / ` diffWithCovers() ` APIs.
115+
116+ ## License
117+
118+ MIT. The prebuilt binaries statically include
119+ [ HDiffPatch] ( https://github.com/sisong/HDiffPatch ) (MIT) and the
120+ [ LZMA SDK] ( https://github.com/sisong/lzma ) (public domain).
0 commit comments