A high-performance Rust implementation of bsdiff and bspatch algorithms with Node.js bindings
npm install @bsdiff-rust/nodeA 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
``bash`
pnpm install @bsdiff-rust/node
`javascript
const 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')
`
`typescript
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
`typescript
// 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
patch(oldFile: string, newFile: string, patchFile: string): Promise
`
Need advanced features? See the Complete Guide for performance stats, configuration options, testing, and benchmarks.
`bashRun functional tests
pnpm test
๐ง Development Guide
$3
- Node.js: >= 16 (Latest LTS recommended)
- Rust: >= 1.70
- Package Manager: npm or pnpm
$3
`bash
Install dependencies
pnpm installBuild release version
pnpm buildBuild debug version
pnpm build:debugBuild for specific platform
pnpm build:arm64
`$3
`bash
Code formatting
pnpm formatCode linting
pnpm lintRun tests
pnpm testPerformance testing
pnpm bench
`$3
`
bsdiff-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
`๐ Cross-platform Support
$3
- macOS: ARM64 (Apple Silicon) and x64 (Intel)
- Linux: ARM64 and x64 (GNU and musl)
- Windows: ARM64 and x64 (MSVC)
$3
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
๐ค Contributing
$3
1. Fork the project
2. Create a feature branch (
git checkout -b feature/amazing-feature)
3. Commit your changes (git commit -m 'Add amazing feature')
4. Push to the branch (git push origin feature/amazing-feature)
5. Create a Pull Request$3
- Rust Code: Use
cargo fmt` for formatting- 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