A high-performance binary differential patching library based on Rust and NAPI-RS, providing an optimized bsdiff/bspatch algorithm implementation for Node.js. Built on qbsdiff library with standard BSDIFF40 format support, featuring suffix array algorithms and parallel processing.
- Standard Compatible: Generates standard BSDIFF40 format, fully compatible with bsdiff-node
- Memory Safe: Rust guarantees memory safety and thread safety, high-performance Node.js bindings via napi-rs
- Optimized Compression: Uses bzip2 compression with memory pre-allocation optimizations
- Cross-platform: Supports Windows, macOS, Linux
pnpm install @bsdiff-rust/nodeconst bsdiff = require('@bsdiff-rust/node')
// Synchronous API
bsdiff.diffSync('old-file.zip', 'new-file.zip', 'patch.bin')
bsdiff.patchSync('old-file.zip', 'generated-file.zip', 'patch.bin')
// Asynchronous API
await bsdiff.diff('old-file.zip', 'new-file.zip', 'patch.bin')
await bsdiff.patch('old-file.zip', 'generated-file.zip', 'patch.bin')import { diff, diffSync, patch, patchSync } from '@bsdiff-rust/node'
// Generate and apply patches
await diff('old-file.zip', 'new-file.zip', 'patch.bin')
await patch('old-file.zip', 'generated-file.zip', 'patch.bin')Need performance monitoring or custom configuration? See Complete API Documentation
// Synchronous methods
diffSync(oldFile: string, newFile: string, patchFile: string): void
patchSync(oldFile: string, newFile: string, patchFile: string): void
// Asynchronous methods
diff(oldFile: string, newFile: string, patchFile: string): Promise<void>
patch(oldFile: string, newFile: string, patchFile: string): Promise<void>Need advanced features? See the Complete Guide for performance stats, configuration options, testing, and benchmarks.
# Run functional tests
pnpm test
# Run performance benchmarks
pnpm run bench- Node.js: >= 16 (Latest LTS recommended)
- Rust: >= 1.70
- Package Manager: npm or pnpm
# Install dependencies
pnpm install
# Build release version
pnpm build
# Build debug version
pnpm build:debug
# Build for specific platform
pnpm build:arm64# Code formatting
pnpm format
# Code linting
pnpm lint
# Run tests
pnpm test
# Performance testing
pnpm benchbsdiff-rust/
βββ src/
β βββ lib.rs # NAPI binding entry
β βββ bsdiff_rust.rs # Core Rust implementation
βββ benchmark/
β βββ benchmark.ts # TypeScript benchmarks
βββ test/
β βββ index.ts # Functional tests
β βββ resources/ # Test resource files
βββ index.js # Node.js entry point
βββ index.d.ts # TypeScript type definitions
βββ Cargo.toml # Rust project configuration
βββ package.json # Node.js project configuration
- macOS: ARM64 (Apple Silicon) and x64 (Intel)
- Linux: ARM64 and x64 (GNU and musl)
- Windows: ARM64 and x64 (MSVC)
This project uses napi-rs's multi-package strategy, automatically downloading precompiled binaries for the corresponding platform during installation:
npm/
βββ @bsdiff-rust/darwin-arm64/ # macOS ARM64
βββ @bsdiff-rust/darwin-x64/ # macOS x64
βββ @bsdiff-rust/linux-arm64-gnu/ # Linux ARM64 glibc
βββ @bsdiff-rust/linux-x64-gnu/ # Linux x64 glibc
βββ @bsdiff-rust/linux-arm64-musl/ # Linux ARM64 musl
βββ @bsdiff-rust/linux-x64-musl/ # Linux x64 musl
βββ ...
Advantages:
- π Fast Installation: No compilation needed, direct download of precompiled binaries
- π¦ On-demand Download: Only downloads files needed for the current platform
- π‘οΈ Stable and Reliable: Avoids installation failures due to compilation environment issues
- Fork the project
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Create a Pull Request
- Rust Code: Use
cargo fmtfor formatting - JavaScript/TypeScript: Use Prettier for formatting
- Commit Messages: Use clear English descriptions
- Complete Guide - API reference, testing, and performance benchmarks
- bsdiff Original Algorithm - Colin Percival's original implementation
- NAPI-RS Documentation - Node.js binding framework
- qbsdiff Library - Underlying Rust implementation
β If this project helps you, please give it a star!
π Found an issue? Feel free to submit an Issue
π‘ Have suggestions for improvement? Welcome to submit a Pull Request