xpatch-rs-native
v0.4.2
Published
High-performance delta compression library with automatic algorithm selection
Maintainers
Readme
xpatch-rs-native
Native Node.js bindings for xpatch - maximum performance delta compression.
npm install xpatch-rs-nativeNote: This package provides native bindings for maximum performance (~10-30% faster than WASM). For most use cases, consider
xpatch-rsinstead, which uses WASM and works in both browsers and Node.js with a smaller package size (~890KB vs ~2MB per platform).
| Package | Size | Platforms | Performance |
|---------|------|-----------|-------------|
| xpatch-rs | ~890KB | Browser + Node.js | Fast |
| xpatch-rs-native | ~2MB/platform | Node.js only | Fastest |
Quick Start
const xpatch = require('xpatch-rs-native');
// Create a delta patch
const base = Buffer.from('Hello, World!');
const newData = Buffer.from('Hello, Node!');
const delta = xpatch.encode(0, base, newData);
console.log(`Delta size: ${delta.length} bytes`);
// Apply the patch
const reconstructed = xpatch.decode(base, delta);
console.log(reconstructed.equals(newData)); // true
// Extract metadata tag
const tag = xpatch.getTag(delta);
console.log(`Tag: ${tag}`);TypeScript Support
TypeScript definitions are included:
import { encode, decode, getTag } from 'xpatch-rs-native';
const base = Buffer.from('Hello, World!');
const newData = Buffer.from('Hello, TypeScript!');
const delta: Buffer = encode(0, base, newData);
const reconstructed: Buffer = decode(base, delta);
const tag: number = getTag(delta);API Reference
encode(tag, baseData, newData, enableZstd?) => Buffer
Creates a delta patch between baseData and newData.
Parameters:
tag(number): Metadata tag to embed (0-4294967295)baseData(Buffer): Original datanewData(Buffer): New dataenableZstd(boolean, optional): Enable zstd compression (default: true)
Returns: Buffer - The encoded delta patch
decode(baseData, delta) => Buffer
Reconstructs newData from baseData and a delta patch.
Parameters:
baseData(Buffer): Original datadelta(Buffer): Delta patch created byencode()
Returns: Buffer - The reconstructed new data
Throws: Error if delta is invalid
getTag(delta) => number
Extracts the metadata tag from a delta patch without decoding.
Parameters:
delta(Buffer): Delta patch
Returns: number - The embedded tag
Throws: Error if delta is invalid
Performance
xpatch achieves exceptional compression ratios on real-world data:
- 99.8% compression on typical code changes
- 2 byte median delta for sequential edits
- Instant decoding (<1µs for most patches)
- 40-55 GB/s throughput for encoding
Use Cases
Perfect for:
- Performance-critical Node.js server applications
- High-throughput data processing pipelines
- Real-time collaborative editing backends
- Version control system backends
Building from Source
cd crates/xpatch-node-native
npm install
npm run buildFor development builds:
npm run build:debugSupported Platforms
Pre-built binaries are available for:
- Linux (x64, ARM64, musl)
- macOS (Intel, Apple Silicon)
- Windows (x64, ARM64)
License
This project is dual-licensed:
- AGPL-3.0-or-later for open-source use
- Commercial license available at [email protected]
See LICENSE-AGPL.txt and LICENSE-COMMERCIAL.txt for details.
Links
- GitHub Repository
- Demo Editor
- xpatch-rs (WASM - recommended for most use cases)
