Skip to content

Commit 15b2df5

Browse files
committed
feat: expose verified diff capabilities
1 parent 9b77951 commit 15b2df5

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ returns `outDiffPath`; async callback signature is `(err, outDiffPath)`.
6060
a larger window catches longer-distance content moves at roughly linear
6161
additional memory.
6262

63+
### capabilities
64+
65+
`capabilities.diffStreamVerifiesOutput`,
66+
`capabilities.diffSingleStreamVerifiesOutput`, and
67+
`capabilities.diffWindowVerifiesOutput` are `true`. Each native diff function
68+
applies and compares the generated patch before it returns, so orchestration
69+
layers can avoid running a redundant second round-trip check.
70+
6371
### patchSingleStream(oldPath, diffPath, outNewPath[, cb])
6472

6573
Apply a single-compressed hpatch payload created by `diff` or

index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ export interface NativeAddon {
6161

6262
export const native: NativeAddon;
6363

64+
export interface HdiffpatchCapabilities {
65+
readonly diffStreamVerifiesOutput: true;
66+
readonly diffSingleStreamVerifiesOutput: true;
67+
readonly diffWindowVerifiesOutput: true;
68+
}
69+
70+
/** Native diff functions apply and compare their output before returning. */
71+
export const capabilities: HdiffpatchCapabilities;
72+
6473
export function diff(oldBuf: BinaryLike, newBuf: BinaryLike): Buffer;
6574
export function diff(
6675
oldBuf: BinaryLike,
@@ -147,6 +156,7 @@ export function diffWindow(
147156

148157
declare const hdiffpatch: {
149158
native: NativeAddon;
159+
capabilities: HdiffpatchCapabilities;
150160
diff: typeof diff;
151161
patch: typeof patch;
152162
diffStream: typeof diffStream;

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,12 @@ exports.patchStream = native.patchStream;
3838
exports.diffSingleStream = native.diffSingleStream;
3939
exports.patchSingleStream = native.patchSingleStream;
4040
exports.diffWindow = native.diffWindow;
41+
42+
// Every native diff entry point performs a complete apply-and-compare check
43+
// before returning. Consumers that would otherwise repeat the same round trip
44+
// can use these explicit capabilities to safely avoid duplicate work.
45+
exports.capabilities = Object.freeze({
46+
diffStreamVerifiesOutput: true,
47+
diffSingleStreamVerifiesOutput: true,
48+
diffWindowVerifiesOutput: true,
49+
});

test/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ function assertHeaderPrefix(diffData, prefix) {
2222
assert.deepStrictEqual(diffData.subarray(0, expected.length), expected);
2323
}
2424

25+
assert.deepStrictEqual(hdiffpatch.capabilities, {
26+
diffStreamVerifiesOutput: true,
27+
diffSingleStreamVerifiesOutput: true,
28+
diffWindowVerifiesOutput: true
29+
});
30+
assert(Object.isFrozen(hdiffpatch.capabilities));
31+
2532
console.log("Test 1: diff + patch = original (sync)...");
2633
var oldData = crypto.randomBytes(40960);
2734
var newData = Buffer.concat([

0 commit comments

Comments
 (0)