Coder Social home page Coder Social logo

php-bsdiff's Introduction

php-bsdiff

Build Status PHP version

bsdiff is a PHP extension to build and apply patches to binary files.

This PHP extension is based on the bsdiff and bspatch libraries maintained by Matthew Endsley. The original algorithm and implementation was developed by Colin Percival. The algorithm is detailed in Colin's paper, Naïve Differences of Executable Code. For more information, visit his website at http://www.daemonology.net/bsdiff/.


Requirements

  • PHP 7.2 to PHP 8.x
  • BZip2 1.0+
  • Linux, macOS, or Windows

Installation

Install via PECL

pecl install bsdiff

# or, if you want to install it without the prompts (i.e., using default installation option(s)):
yes '' | pecl install bsdiff

In case BZip2 can't be found automatically, use option with-bz2 to specify the installation directory of BZip2. e.g.,

pecl install -D 'with-bz2="/usr/local/opt/bzip2"' bsdiff # If BZip2 is installed via Homebrew on MacOS.

Manual Installation

phpize
./configure
make
make test
make install

Once done, add the following line to your php.ini file:

extension=bsdiff.so

In case BZip2 can't be found automatically, use option --with-bz2 to specify the installation directory of BZip2. e.g.,

./configure --with-bz2=/usr/local/opt/bzip2 # If BZip2 is installed via Homebrew on MacOS.

Usage

There are two PHP functions added by the extension:

/**
  * @throws \BsdiffException If there is any error happens.
  */
function bsdiff_diff(string $old_file, string $new_file, string $diff_file): void {}

/**
  * @throws \BsdiffException If there is any error happens.
  */
function bsdiff_patch(string $old_file, string $new_file, string $diff_file): void {}

Here is an example on how to use the extension:

<?php
$old_file  = '/path/to/the/old/file';
$new_file  = '/path/to/the/new/file';
$diff_file = '/path/to/the/diff/file';

// To create the diff file.
try {
    bsdiff_diff($old_file, $new_file, $diff_file);
} catch (BsdiffException $e) {
    // Handle the exception.
}

// To apply the diff file.
$patched_file = '/path/to/the/patched/file';
try {
    bsdiff_patch($old_file, $patched_file, $diff_file);
} catch (BsdiffException $e) {
    // Handle the exception.
}
// File $patched_file will have exactly the same content as file $new_file.

License

The PHP license.

php-bsdiff's People

Contributors

deminy avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.