## String Diff **Path:** `src/string-diff.ts` **Export:** `calculateStringDiff`, `applyStringDiff`, `calculateDiffSavings`, `shouldUseDiff`, `StringDiff` ### What it does Efficiently encodes string changes by finding common prefix and suffix, only encoding the differing middle section. ### Key API | Function | Description | |----------|-------------| | `calculateStringDiff(previous, current)` | Compute `{ prefixLen, suffixLen, middleLen, middle }` | | `applyStringDiff(previous, diff)` | Reconstruct current string from diff | | `calculateDiffSavings(previous, current, diff)` | Percentage savings from diff encoding | | `shouldUseDiff(previous, current, threshold?)` | Decide whether diff encoding is worthwhile | ### Format `[prefixLen][suffixLen][middleLen][middleChars...]` — each length field is 1 byte. ### Used by - Delta compression for string fields in game state - Network protocols with repetitive string data