
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
advanced-patch-generator-js
Advanced tools
Advanced patch manager using Xdelta for efficient patch creation and application with progress support, events, and error handling
Advanced patch manager using Xdelta for efficient patch creation and application with progress support, events, and error handling.
Advanced Patch Generator requires Xdelta3 installed on the system.
# Using Scoop
scoop install xdelta3
# Using Chocolatey
choco install xdelta3
# Using Winget
winget install xdelta3
# Or download manually from https://github.com/jmacd/xdelta/releases
# Using Homebrew
brew install xdelta
# Using MacPorts
sudo port install xdelta3
# Ubuntu/Debian
sudo apt-get install xdelta3
# CentOS/RHEL
sudo yum install xdelta3
# Arch Linux
sudo pacman -S xdelta3
npm install advanced-patch-generator
import AdvancedPatchGenerator from 'advanced-patch-generator';
// Create an instance
const patchGen = new AdvancedPatchGenerator({
compression: 6,
verify: true,
showProgress: true
});
// Create a patch
const result = await patchGen.createPatch(
'original_file.txt',
'new_file.txt',
'patch.xdelta'
);
if (result.success) {
console.log('✅ Patch created successfully!');
console.log(`Size: ${result.patchFile.sizeFormatted}`);
}
const patchGen = new AdvancedPatchGenerator({
// Basic settings
compression: 6, // Compression level (0-9)
verify: true, // Verify integrity
showProgress: true, // Show default progress
// Large file settings
largeFileThreshold: 100 * 1024 * 1024, // 100MB
timeout: 600000, // 10 minutes
memoryLimit: 1000 * 1024 * 1024, // 1GB
// Optional callbacks
onProgress: (progress) => {
console.log(`Progress: ${progress.percentage}%`);
},
onError: (error) => {
console.error(`Error: ${error.message}`);
},
onComplete: (result) => {
console.log('Operation completed!');
}
});
The class extends EventEmitter
, allowing you to listen to events:
// Listen to progress events
patchGen.on('progress', (data) => {
console.log(`${data.percentage}% - ${data.message}`);
});
// Listen to error events
patchGen.on('error', (error) => {
console.error(`Error: ${error.message}`);
});
// Listen to completion events
patchGen.on('complete', (result) => {
console.log('Operation completed!');
});
createPatch(oldFile, newFile, patchFile, options)
Creates a patch between two files.
const result = await patchGen.createPatch(
'original_file.txt',
'new_file.txt',
'patch.xdelta',
{ compression: 9 }
);
if (result.success) {
console.log(`Patch created: ${result.patchFile.sizeFormatted}`);
console.log(`Duration: ${result.metrics.durationFormatted}`);
console.log(`Compression: ${result.metrics.compressionRatio}%`);
}
applyPatch(oldFile, patchFile, newFile, options)
Applies a patch to a file.
const result = await patchGen.applyPatch(
'original_file.txt',
'patch.xdelta',
'applied_file.txt'
);
if (result.success) {
console.log('Patch applied successfully!');
}
verifyPatch(oldFile, patchFile, expectedFile)
Verifies the integrity of a patch.
const result = await patchGen.verifyPatch(
'original_file.txt',
'patch.xdelta',
'expected_file.txt'
);
if (result.isValid) {
console.log('✅ Patch is valid!');
} else {
console.log('❌ Patch is invalid!');
}
createBatchPatches(oldDir, newDir, patchesDir, options)
Creates patches in batch for multiple files.
const results = await patchGen.createBatchPatches(
'original_folder',
'new_folder',
'patches_folder',
{ maxParallel: 4 }
);
console.log(`Processed: ${results.length} files`);
applyBatchPatches(oldDir, patchesDir, outputDir, options)
Applies patches in batch.
const results = await patchGen.applyBatchPatches(
'original_folder',
'patches_folder',
'output_folder'
);
const successCount = results.filter(r => r.status === 'success').length;
console.log(`Successfully applied: ${successCount}`);
try {
const result = await patchGen.createPatch(
'nonexistent_file.txt',
'new_file.txt',
'patch.xdelta'
);
if (!result.success) {
console.error(`Error: ${result.error}`);
console.log(`Duration: ${result.durationFormatted}`);
}
} catch (error) {
console.error('Caught exception:', (error as Error).message);
}
const patchGen = new AdvancedPatchGenerator({
compression: 6,
verify: true,
showProgress: true,
onProgress: (progress) => {
console.log(`📊 ${progress.percentage}% - ${progress.message}`);
},
onError: (error) => {
console.error(`❌ ${error.message}`);
},
onComplete: (result) => {
console.log(`✅ Patch created: ${result.patchFile.sizeFormatted}`);
}
});
const result = await patchGen.createPatch(
'original_file.txt',
'new_file.txt',
'patch.xdelta'
);
const patchGen = new AdvancedPatchGenerator({
compression: 9,
showProgress: false
});
// Custom progress bar
patchGen.on('progress', (data) => {
const bar = '█'.repeat(Math.floor(data.percentage / 5)) +
'░'.repeat(20 - Math.floor(data.percentage / 5));
process.stdout.write(`\r📊 [${bar}] ${data.percentage}%`);
});
patchGen.on('complete', (result) => {
console.log(`\n✅ Completed! ${result.patchFile.sizeFormatted}`);
});
await patchGen.createPatch('old.txt', 'new.txt', 'patch.xdelta');
const patchGen = new AdvancedPatchGenerator({
compression: 3, // Lower compression for large files
largeFileThreshold: 100 * 1024 * 1024, // 100MB
timeout: 600000, // 10 minutes
memoryLimit: 1000 * 1024 * 1024 // 1GB
});
const result = await patchGen.createPatch(
'large_original_file.bin',
'large_new_file.bin',
'large_patch.xdelta'
);
if (result.success) {
console.log(`Method used: ${result.metrics.isLargeFile ? 'Chunked' : 'Standard'}`);
}
const patchGen = new AdvancedPatchGenerator({
compression: 6,
verify: true
});
// Create patches in batch
const createResults = await patchGen.createBatchPatches(
'original_folder',
'new_folder',
'patches_folder',
{ maxParallel: 4 }
);
console.log(`Patches created: ${createResults.length}`);
// Apply patches in batch
const applyResults = await patchGen.applyBatchPatches(
'original_folder',
'patches_folder',
'output_folder'
);
const successCount = applyResults.filter(r => r.status === 'success').length;
console.log(`Successfully applied: ${successCount}/${applyResults.length}`);
const patchGen = new AdvancedPatchGenerator({
compression: 9, // Maximum compression (slower)
// compression: 0, // No compression (faster)
// compression: 6, // Balanced compression (default)
});
const patchGen = new AdvancedPatchGenerator({
largeFileThreshold: 500 * 1024 * 1024, // 500MB
timeout: 1800000, // 30 minutes
memoryLimit: 2000 * 1024 * 1024, // 2GB
});
const results = await patchGen.createBatchPatches(
'old_dir',
'new_dir',
'patches_dir',
{
maxParallel: 4, // Maximum 4 simultaneous operations
compression: 6,
verify: true
}
);
# Windows (Recomendado)
choco install xdelta3
# Windows (Alternativas)
scoop install xdelta3
winget install xdelta3
# macOS
brew install xdelta
# Linux
sudo apt-get install xdelta3
Problema: "Xdelta3 not found on system" mesmo após instalação
# Solução 1: Reiniciar o terminal
# Feche e abra um novo terminal/PowerShell
# Solução 2: Verificar instalação
where xdelta3
xdelta3 -h
# Solução 3: Configurar caminho manualmente
const patchGen = new AdvancedPatchGenerator({
xdeltaPath: "C:\\ProgramData\\chocolatey\\bin\\xdelta3.exe"
});
Problema: Espaços nos caminhos dos arquivos
// A biblioteca agora trata automaticamente espaços nos caminhos
// Mas se ainda houver problemas, use caminhos sem espaços
const result = await patchGen.createPatch(
'C:\\My Files\\old.txt', // ✅ Funciona
'C:\\My Files\\new.txt', // ✅ Funciona
'C:\\My Files\\patch.xdelta' // ✅ Funciona
);
timeout: 1800000
(30 minutes)memoryLimit: 2000 * 1024 * 1024
(2GB)compression: 3
For large files (>100MB):
For batch operations:
maxParallel: 4
for optimal performanceFor production use:
This project is licensed under the MIT License - see the LICENSE file for details.
⭐ If this project was useful to you, consider giving it a star on GitHub!
FAQs
Advanced patch manager using Xdelta for efficient patch creation and application with progress support, events, and error handling
We found that advanced-patch-generator-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.