### Development: Project Setup with Axogen Source: https://github.com/imgajeed76/xpatch/blob/master/README.md Illustrates the initial setup and common development commands for the xpatch project using the `axogen` tool. This includes installing dependencies, running setup, building components, executing tests, and managing code quality. ```bash # Install dependencies (requires Bun) bun install # Run interactive setup (detects tools, builds everything) axogen run setup # Build components axogen run build rust # Core Rust library axogen run build c # C/C++ bindings axogen run build python # Python bindings axogen run build node # Node.js bindings axogen run build all # Everything # Run tests axogen run test # All tests axogen run test rust # Rust only axogen run test python # Python only axogen run test node # Node only # Local testing (prepare packages for use in other projects) axogen run local rust # Prepare Rust library axogen run local python # Prepare Python package axogen run local node # Prepare Node.js package # Code quality axogen run fmt # Format all code axogen run lint # Lint all code # Examples axogen run example basic # Run basic example axogen run example tags # Run tags example # Quick reference axogen run howto # Show all documentation axogen run howto build # Build instructions axogen run howto bench # Benchmark guide axogen run howto local # Local testing guide ``` -------------------------------- ### Manual Setup for Node.js Example Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-wasm/README.md Steps to manually build the WASM module for Node.js and run a specific example script. ```bash # Node.js axogen run build wasm --target nodejs node crates/xpatch-wasm/examples/node/example.js ``` -------------------------------- ### Build and Run Examples (Bash) Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-c/README.md Commands to build and execute the example programs for the xpatch C/C++ bindings. Navigate to the examples directory, then use 'make' to build and 'make run' to execute. ```bash cd examples make make run ``` -------------------------------- ### Quick Start: Create and Apply Delta Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch/src/bin/cli/README.md A quick guide to creating a delta patch using 'xpatch encode' and applying it using 'xpatch decode'. ```bash # Create a delta xpatch encode old.bin new.bin -o patch.xdelta # Apply the delta xpatch decode old.bin patch.xdelta -o restored.bin # Verify they match diff new.bin restored.bin ``` -------------------------------- ### Manual Setup for Browser Example Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-wasm/README.md Steps to manually build the WASM module for web and serve the browser example locally using Python's http.server. ```bash # Browser axogen run build wasm --target web cd crates/xpatch-wasm && python3 -m http.server 8080 # Open http://localhost:8080/examples/browser/ ``` -------------------------------- ### xpatch CLI Examples Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Examples demonstrating the command-line interface for xpatch, including encoding, decoding, and showing patch information. ```bash # Encode a delta cargo run -p xpatch --features cli -- encode base.txt new.txt -o patch.xp # Decode a delta cargo run -p xpatch --features cli -- decode base.txt patch.xp -o restored.txt # Show delta information cargo run -p xpatch --features cli -- info patch.xp ``` -------------------------------- ### Python Development Workflow for xpatch Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Steps to set up and develop the Python bindings for xpatch. Includes virtual environment setup, dependency installation, and running tests. ```bash cd crates/xpatch-python python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install maturin maturin develop python tests/test_xpatch.py ``` -------------------------------- ### Rust: Run xpatch Examples Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch/README.md Illustrates how to execute example code provided with the xpatch library using Cargo. These commands allow users to run specific examples like 'basic' and 'tags' to see the library in action. ```bash cargo run --example basic cargo run --example tags ``` -------------------------------- ### Run xpatch Examples using Axogen Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Commands to list and run examples for the xpatch project using the axogen runner. Supports running specific examples by name. ```bash axogen run example list # List all examples axogen run example basic # Run basic example axogen run example tags # Run tags example ``` -------------------------------- ### Install xpatch CLI Tool Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch/src/bin/cli/README.md Instructions for installing the xpatch CLI tool using Cargo from crates.io or by building from source. ```bash cargo install xpatch --features cli ``` ```bash git clone https://github.com/ImGajeed76/xpatch cd xpatch cargo build --release --features cli # Binary will be at target/release/xpatch ``` -------------------------------- ### Build and Install Python Wheel Locally Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Instructions for building a release wheel for the xpatch-python package using maturin and then installing it locally within a Python virtual environment. ```bash # Build the wheel cd crates/xpatch-python maturin build --release # Install the wheel in your test project's venv pip install target/wheels/xpatch_rs-*.whl ``` -------------------------------- ### Run Examples with axogen Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-wasm/README.md Commands to run xpatch examples for browser and Node.js using the axogen build tool. This automatically handles building and execution. ```bash # Browser demo (builds for web, starts server at localhost:8080) axogen run example browser --lang=wasm # Node.js example (builds for nodejs, runs all 5 examples) axogen run example node --lang=wasm # List all available examples axogen run example list ``` -------------------------------- ### Test Node.js Package Locally with Direct Path Installation Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Methods for installing the xpatch-node-native package directly from a local path using npm or bun, useful for quick testing without linking. ```bash # In your test project npm install /path/to/xpatch/crates/xpatch-node-native # Or bun add /path/to/xpatch/crates/xpatch-node-native ``` -------------------------------- ### C/C++ Development Workflow for xpatch Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Steps to build, test, and run examples for the C/C++ bindings of xpatch. Includes manual build commands and information about the generated distribution package. ```bash # Build the C bindings axogen run build c # Or manually cd crates/xpatch-c cargo build --release cargo test # Build and run examples cd examples make ./basic # The build creates a distribution package at: # crates/xpatch-c/dist/ # ├── libxpatch_c.{so,dylib,dll} # ├── xpatch.h # └── README.md ``` -------------------------------- ### Node.js Development Workflow for xpatch Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Steps to set up and develop the Node.js native bindings for xpatch. Supports both Bun and npm for installation and building. ```bash cd crates/xpatch-node-native bun install # Or: npm install bun run build:debug # Or: npm run build:debug bun test.js # Or: npm test ``` -------------------------------- ### Test Python Package Locally with Pip Editable Install Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Demonstrates how to perform an editable installation of the xpatch-python package using pip, enabling changes in the source code to be reflected immediately without reinstallation. ```bash # In xpatch-python directory cd crates/xpatch-python pip install -e . # Or from another project pip install -e /path/to/xpatch/crates/xpatch-python ``` -------------------------------- ### Test Node.js Package Locally via package.json Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md How to specify a local file path for the xpatch-rs dependency in a test project's package.json, followed by running npm install or bun install. ```json { "dependencies": { "xpatch-rs": "file:../path/to/xpatch/crates/xpatch-node-native" } } Then run `npm install` or `bun install`. ``` -------------------------------- ### TypeScript Example: Encoding, Decoding, and Getting Tag Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-node-native/README.md Illustrates how to use the xpatch-rs-native library with TypeScript, including importing the necessary functions and performing encode, decode, and getTag operations. ```typescript 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); ``` -------------------------------- ### Install xpatch-rs-native using npm Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-node-native/README.md This command installs the xpatch-rs-native package, which provides native Node.js bindings for delta compression. Ensure you have Node.js and npm installed. ```bash npm install xpatch-rs-native ``` -------------------------------- ### WebAssembly Development Workflow for xpatch Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Steps to build and test the WebAssembly bindings for xpatch using wasm-pack. Includes commands for different build targets and running examples. ```bash cd crates/xpatch-wasm # Build for browsers wasm-pack build --release --target web # Build for Node.js wasm-pack build --release --target nodejs # Build for bundlers wasm-pack build --release --target bundler # Run tests wasm-pack test --node # Run examples axogen run example browser --lang=wasm # Browser demo (auto-builds & serves) axogen run example node --lang=wasm # Node.js example (auto-builds & runs) ``` -------------------------------- ### Python Delta Compression Example Source: https://github.com/imgajeed76/xpatch/blob/master/README.md Provides a Python example for using the xpatch library to perform delta compression. It demonstrates encoding a base byte string into a delta and then decoding it to retrieve the original new byte string. It also shows how to extract metadata tags. ```python import xpatch base = b"Hello, World!" new = b"Hello, Python!" # Create delta delta = xpatch.encode(0, base, new) # Apply delta reconstructed = xpatch.decode(base, delta) assert reconstructed == new # Extract tag tag = xpatch.get_tag(delta) print(f"Compressed {len(new)} → {len(delta)} bytes") ``` -------------------------------- ### Get Help with Axogen Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Command to display quick reference information and available commands provided by the axogen tool. ```bash axogen run howto ``` -------------------------------- ### Bash: Install xpatch CLI Tool Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch/README.md Demonstrates the command to install the xpatch CLI tool using Cargo, the Rust package manager. This command enables the use of `xpatch` commands directly from the terminal, including the `cli` feature. ```bash cargo install xpatch --features cli ``` -------------------------------- ### C Usage Example for xpatch Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-c/README.md Demonstrates how to use the xpatch C API for encoding and decoding data. It includes necessary headers, encoding a delta, printing its size, decoding the delta, and handling potential errors. Remember to free allocated buffers and error messages. ```c #include #include #include "xpatch.h" int main() { const char* base = "Hello, World!"; const char* new = "Hello, Rust!"; // Encode struct xpatch_XPatchBuffer delta = xpatch_encode( 0, (const uint8_t*)base, strlen(base), (const uint8_t*)new, strlen(new), true ); printf("Delta size: %zu bytes\n", delta.len); // Decode struct xpatch_XPatchResult result = xpatch_decode( (const uint8_t*)base, strlen(base), delta.data, delta.len ); if (result.error_message == NULL) { printf("Success! Decoded %zu bytes\n", result.buffer.len); xpatch_free_buffer(result.buffer); } else { fprintf(stderr, "Error: %s\n", (char*)result.error_message); xpatch_free_error(result.error_message); } xpatch_free_buffer(delta); return 0; } ``` -------------------------------- ### Build xpatch-rs-native from Source in Node.js Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-node-native/README.md Instructions for building the xpatch-rs-native package from its source code. This involves navigating to the native bindings directory, installing dependencies, and running the build script. ```bash cd crates/xpatch-node-native npm install npm run build ``` -------------------------------- ### Bash: xpatch CLI Tool - Encoding, Decoding, and Info Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch/README.md Provides examples of using the xpatch command-line interface (CLI) tool for delta compression operations. It demonstrates how to create a delta patch, apply a patch to restore data, and display information about a patch file. ```bash # Create a delta xpatch encode base.txt new.txt -o patch.xp # Apply a delta xpatch decode base.txt patch.xp -o restored.txt # Show delta info xpatch info patch.xp ``` -------------------------------- ### Link xpatch Library with GCC/Clang (Bash) Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-c/README.md Example command for linking the compiled xpatch C library with your application using GCC or Clang. This command specifies the output executable name, the source file, the include path for xpatch.h, the library path, and the library name. ```bash gcc -o myapp myapp.c -I/path/to/xpatch-c -L/path/to/target/release -lxpatch_c ``` -------------------------------- ### Install xpatch-rs Python Package Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-python/README.md Installs the xpatch-rs library using pip. Note that the package name on PyPI is 'xpatch-rs', but it is imported as 'xpatch' in Python code. ```bash pip install xpatch-rs ``` -------------------------------- ### Example Error Message: File Not Found Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch/src/bin/cli/README.md This snippet shows the typical error message when a specified input file for xpatch is not found. It advises users to verify the existence and correctness of file paths. ```text Error: File not found: input.bin ``` -------------------------------- ### Quick Start: Encode and Decode Delta Patches in Node.js Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-node-native/README.md Demonstrates the basic usage of xpatch-rs-native for creating a delta patch between two buffers and then reconstructing the original data. It also shows how to extract a metadata tag from the delta. ```javascript 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}`); ``` -------------------------------- ### C++ Usage Example for xpatch Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-c/README.md Illustrates the usage of the xpatch C API within a C++ program. It shows how to encode and decode data using std::string and reinterpret_cast for data pointers. Proper memory management by freeing buffers and error messages is essential. ```cpp #include #include #include #include "xpatch.h" int main() { std::string base = "Hello, World!"; std::string new_text = "Hello, C++!"; // Encode auto delta = xpatch_encode( 0, reinterpret_cast(base.data()), base.size(), reinterpret_cast(new_text.data()), new_text.size(), true ); std::cout << "Delta size: " << delta.len << " bytes\n"; // Decode auto result = xpatch_decode( reinterpret_cast(base.data()), base.size(), delta.data, delta.len ); if (result.error_message == nullptr) { std::cout << "Success! Decoded " << result.buffer.len << " bytes\n"; xpatch_free_buffer(result.buffer); } else { std::cerr << "Error: " << reinterpret_cast(result.error_message) << "\n"; xpatch_free_error(result.error_message); } xpatch_free_buffer(delta); return 0; } ``` -------------------------------- ### Manual Python Code Formatting and Linting Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Commands to install and run Python code formatters (black) and linters (mypy, ruff) on the xpatch-python directory. ```bash pip install black mypy ruff black crates/xpatch-python/ ruff check crates/xpatch-python/ ``` -------------------------------- ### Test Node.js Package Locally with npm link Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Guide to testing the xpatch-node-native package locally using npm link. This involves building the package, linking it globally, and then linking it into a test project. ```bash # In xpatch-node-native directory cd crates/xpatch-node-native npm run build npm link # In your test project npm link xpatch-rs ``` -------------------------------- ### C/C++ Delta Compression Example Source: https://github.com/imgajeed76/xpatch/blob/master/README.md Illustrates the usage of the xpatch C/C++ bindings for delta compression. It shows how to encode a base string into a delta and then decode it to reconstruct the new string. Memory management for buffers is handled via xpatch_free_buffer. ```c #include #include #include "xpatch.h" int main() { const char* base = "Hello, World!"; const char* new = "Hello, C!"; // Encode struct xpatch_XPatchBuffer delta = xpatch_encode( 0, (const uint8_t*)base, strlen(base), (const uint8_t*)new, strlen(new), true ); printf("Compressed %zu → %zu bytes\n", strlen(new), delta.len); // Decode struct xpatch_XPatchResult result = xpatch_decode( (const uint8_t*)base, strlen(base), delta.data, delta.len ); if (result.error_message == NULL) { printf("Success!\n"); xpatch_free_buffer(result.buffer); } xpatch_free_buffer(delta); return 0; } ``` -------------------------------- ### Commit Changes with Conventional Commits Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Example of staging all changes and committing them with a message following the Conventional Commits specification, outlining commit types like 'feat:', 'fix:', etc. ```bash git add . git commit -m "feat: add new feature" ``` -------------------------------- ### Test Python Package Locally with Maturin Develop Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Steps to perform a development installation of the xpatch-python package using maturin develop, allowing immediate import and testing in Python scripts. ```bash # In xpatch-python directory cd crates/xpatch-python maturin develop # Now you can import xpatch in any Python script on the same system python -c "import xpatch; print(xpatch.__version__)" ``` -------------------------------- ### Build xpatch-rs from Source Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-python/README.md Builds the xpatch-rs Python bindings from source using maturin. This involves navigating to the Python crate directory, installing maturin, and then developing the package in place. ```bash cd crates/xpatch-python pip install maturin maturin develop ``` -------------------------------- ### Example Error Message: Insufficient Memory Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch/src/bin/cli/README.md This snippet displays the error message indicating insufficient available RAM for the xpatch operation. It recommends using a machine with more memory or employing the library API for streaming. ```text Error: Insufficient memory Required: ~4.2 GB Total RAM: 4.0 GB ``` -------------------------------- ### Rust: Delta Compression and Decompression with xpatch Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch/README.md Demonstrates the basic usage of the xpatch library in Rust for creating and applying delta compression. It encodes a base byte slice into a delta and then decodes it back to reconstruct the original data. This example requires the `xpatch` crate as a dependency. ```rust use xpatch::delta; fn main() { let base = b"Hello, World!"; let new = b"Hello, Rust!"; // Create delta let delta = delta::encode(0, base, new, true); // Apply delta let reconstructed = delta::decode(base, &delta).unwrap(); assert_eq!(reconstructed, new); // Extract tag let tag = delta::get_tag(&delta).unwrap(); println!("Compressed {} → {} bytes", new.len(), delta.len()); } ``` -------------------------------- ### Install xpatch-rs WASM Package Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-wasm/README.md Installs the recommended xpatch-rs WebAssembly package for universal use in browsers and Node.js via npm. ```bash npm install xpatch-rs ``` -------------------------------- ### Run xpatch Benchmarks Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Commands to run benchmarks for the xpatch project. Includes options for stress tests, real-world git benchmarks, and using specific presets. ```bash # Stress test benchmark cargo bench --bench stress # Real-world git benchmark cargo bench --bench git_real_world # With specific preset XPATCH_PRESET=tokio cargo bench --bench git_real_world ``` -------------------------------- ### Development: Manual Build Commands Source: https://github.com/imgajeed76/xpatch/blob/master/README.md Provides instructions for manually building and testing components of the xpatch project without using `axogen`. This covers Rust, Python, and Node.js specific build processes. ```bash # Rust car go build --all car go test -p xpatch # Python cd crates/xpatch-python pip install maturin maturin develop # Node.js cd crates/xpatch-node npm install && npm run build ``` -------------------------------- ### Create a Feature Branch Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Git command to create a new branch for developing a feature, starting from the current checkout. ```bash git checkout -b feature/my-feature ``` -------------------------------- ### Testing WASM Bindings for xpatch Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Instructions for testing WebAssembly bindings of xpatch, recommending the use of the axogen runner. ```bash # Via axogen (recommended) axogen run test wasm ``` -------------------------------- ### Rust: Run xpatch Benchmarks Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch/README.md Shows commands for running benchmark tests for the xpatch library. It includes commands for quick stress tests and more comprehensive benchmarks using real-world git repository data, with options for setting environment variables like `XPATCH_PRESET`. ```bash # Quick stress tests cargo bench --bench stress # Real-world git repository benchmarks XPATCH_PRESET=tokio cargo bench --bench git_real_world ``` -------------------------------- ### Enable Verbose Logging in Rust CLI Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Example of running the Rust CLI application with verbose logging enabled via the RUST_LOG environment variable, useful for debugging. ```bash RUST_LOG=debug cargo run -p xpatch --features cli -- encode base.txt new.txt -o patch.xp ``` -------------------------------- ### Run xpatch Benchmarks Source: https://github.com/imgajeed76/xpatch/blob/master/README.md Provides commands to run benchmark tests for xpatch, including quick stress tests and real-world Git repository benchmarks. It also lists available environment variables for customizing the benchmark runs. ```bash # Quick Stress Tests car go bench --bench stress # Real-World Git Repository Benchmarks # Use a preset repository XPATCH_PRESET=tokio cargo bench --bench git_real_world # Test all files at HEAD XPATCH_PRESET=tokio XPATCH_ALL_FILES_HEAD=true cargo bench --bench git_real_world # Build cache for faster repeated runs XPATCH_PRESET=tokio XPATCH_BUILD_CACHE=true XPATCH_CACHE_DIR=./cache cargo bench --bench git_real_world # Use cache XPATCH_PRESET=tokio XPATCH_USE_CACHE=true XPATCH_CACHE_DIR=./cache cargo bench --bench git_real_world # Customize search depth and other options XPATCH_PRESET=tokio XPATCH_MAX_TAG_DEPTH=32 XPATCH_MAX_COMMITS=200 cargo bench --bench git_real_world ``` -------------------------------- ### Browser Usage with Bundler Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-wasm/README.md Example of initializing and using xpatch WASM functions (encode, decode, version) in a browser environment when using a module bundler. ```javascript import init, { encode, decode, version } from './pkg/xpatch_wasm.js'; await init(); console.log(`xpatch version: ${version()}`); const encoder = new TextEncoder(); const base = encoder.encode("Hello, World!"); const newData = encoder.encode("Hello, WebAssembly!"); const delta = encode(0, base, newData, true); const reconstructed = decode(base, delta); console.log(new TextDecoder().decode(reconstructed)); ``` -------------------------------- ### Run Tests and Linting with Axogen Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Commands to execute the project's test suite and run linters using the axogen tool. ```bash axogen run test axogen run lint ``` -------------------------------- ### Example Error Message: Verification Failed Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch/src/bin/cli/README.md This snippet shows the error message when the verification process of the reconstructed output fails, indicating a mismatch with the original file. It suggests re-encoding the file. ```text Error: Verification failed: reconstructed output does not match original ``` -------------------------------- ### Test Rust Library Locally with Path Dependencies Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Instructions for testing the Rust xpatch library locally by using path dependencies in the test project's Cargo.toml file or via cargo add. ```toml [dependencies] xpatch = { path = "/path/to/xpatch/crates/xpatch" } ``` ```bash # In your test project car go add --path /path/to/xpatch/crates/xpatch ``` -------------------------------- ### Build xpatch Manually (Node.js) Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Commands to manually build the Node.js native bindings for xpatch. Supports both Bun and npm package managers. ```bash cd crates/xpatch-node-native bun install && bun run build # If using Bun npm install && npm run build # If using npm ``` -------------------------------- ### Browser Usage without Bundler Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-wasm/README.md Example of initializing and using xpatch WASM functions (encode, decode) in a browser environment using a script tag, without a module bundler. ```html ``` -------------------------------- ### Run All xpatch Tests Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Command to execute all tests for the xpatch project using the axogen runner. ```bash axogen run test ``` -------------------------------- ### xpatch Get Tag Function (C) Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch-c/README.md Extracts the metadata tag from a delta patch. It takes a pointer to the delta data and its length, and a pointer to store the extracted tag. Returns NULL on success or an error message string on failure. ```c int8_t *xpatch_get_tag( const uint8_t *delta, uintptr_t delta_len, uintptr_t *tag_out ); ``` -------------------------------- ### Efficient Delta Encoding with Tags in Rust Source: https://github.com/imgajeed76/xpatch/blob/master/README.md Illustrates how to use tags in Rust for efficient delta compression, especially when reverting to older versions. It shows the difference in delta size between a naive approach and an optimized approach using tags. ```rust use xpatch::delta; fn main() { let v1 = b"Hello"; let v2 = b"Hello, World!"; let v3 = b"Hello"; // Same as v1! println!("=== Naive Approach ==="); // Always compare with immediate predecessor let delta_v1_to_v2 = delta::encode(0, v1, v2, false); println!("v1 -> v2 delta size: {} bytes", delta_v1_to_v2.len()); let delta_v2_to_v3 = delta::encode(0, v2, v3, false); println!("v2 -> v3 delta size: {} bytes", delta_v2_to_v3.len()); let naive_total = delta_v1_to_v2.len() + delta_v2_to_v3.len(); println!("Naive total: {} bytes\n", naive_total); println!("=== Optimized Approach ==="); // Compare v3 with v1 instead - they're identical! let delta_v1_to_v3 = delta::encode(1, v1, v3, false); println!("v1 -> v3 delta size: {} bytes", delta_v1_to_v3.len()); println!("Tag=1 indicates base version\n"); // Verify decoding works let reconstructed = delta::decode(v1, &delta_v1_to_v3[..]).unwrap(); assert_eq!(reconstructed, v3); let tag = delta::get_tag(&delta_v1_to_v3[..]).unwrap(); println!("Tag extracted: {}", tag); } ``` -------------------------------- ### Example Error Message: Output File Exists Source: https://github.com/imgajeed76/xpatch/blob/master/crates/xpatch/src/bin/cli/README.md This snippet illustrates the error message generated when xpatch attempts to write to an output file that already exists. It suggests using the `--force` flag or manually removing the existing file. ```text Error: Output file already exists: output.xdelta Use --force to overwrite ``` -------------------------------- ### Build xpatch Manually (Rust) Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Commands to manually build the xpatch project in Rust for all targets. Includes options for standard and release builds. ```bash cargo build --all cargo build --all --release # Release mode ``` -------------------------------- ### Node.js Native: Encode, Decode, and Get Tag Source: https://github.com/imgajeed76/xpatch/blob/master/README.md Shows how to use the `xpatch-rs-native` module in Node.js for creating deltas, applying them to reconstruct data, and retrieving tags. This version uses Node.js Buffers and native bindings. Requires `xpatch-rs-native`. ```typescript import { encode, decode, getTag } from "xpatch-rs-native"; const base = Buffer.from("Hello, World!"); const newData = Buffer.from("Hello, Node!"); // Create delta const delta = encode(0, base, newData); // Apply delta const reconstructed = decode(base, delta); console.log(reconstructed.equals(newData)); // true // Extract tag const tag = getTag(delta); console.log(`Compressed ${newData.length} → ${delta.length} bytes`); ``` -------------------------------- ### Build xpatch Manually (WebAssembly) Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Commands to manually build WebAssembly bindings for xpatch using wasm-pack. Supports targets for browsers, Node.js, and bundlers. ```bash cd crates/xpatch-wasm wasm-pack build --release --target web # For browsers wasm-pack build --release --target nodejs # For Node.js wasm-pack build --release --target bundler # For bundlers ``` -------------------------------- ### Build xpatch Manually (C/C++) Source: https://github.com/imgajeed76/xpatch/blob/master/DEVELOPMENT.md Command to manually build the C/C++ bindings for xpatch using cargo. This command performs a release build. ```bash cd crates/xpatch-c cargo build --release ```