All Projects → icedream → go-bsdiff

icedream / go-bsdiff

Licence: BSD-2-Clause license
Golang wrapper for @mendsley's bsdiff C library.

Programming Languages

c
50402 projects - #5 most used programming language
go
31211 projects - #10 most used programming language
M4
1887 projects

Projects that are alternatives of or similar to go-bsdiff

deltaq
Fast and portable delta encoding for .NET in 100% safe, managed code.
Stars: ✭ 26 (+30%)
Mutual labels:  bsdiff, patch
dipa
dipa makes it easy to efficiently delta encode large Rust data structures.
Stars: ✭ 243 (+1115%)
Mutual labels:  patch
react-native-async-load-bundle
This is an example project to build the common bundle file and the differential bundle file using Metro, and load the differential bundle asynchronously in app. Compare with loading the official bundle file synchronously, there was 20% ~ 25%(20 ~ 200 ms) decrease in the load time of react view by using loading the differential bundle asynchronou…
Stars: ✭ 25 (+25%)
Mutual labels:  bsdiff
OpenWrt-UEFI-Support
Add UEFI-Boot Support to Openwrt v19.07 & v18.06 (Unofficial Support)
Stars: ✭ 13 (-35%)
Mutual labels:  patch
OS-X-Yosemite-on-Unsupported-Macs
Install OS X Yosemite on Unsupported Macs
Stars: ✭ 23 (+15%)
Mutual labels:  patch
magento1-open-source-patches
Magento Open Source 1.x patches mirror repository.
Stars: ✭ 38 (+90%)
Mutual labels:  patch
minibsdiff
A miniature, portable version of bsdiff.
Stars: ✭ 115 (+475%)
Mutual labels:  bsdiff
Mirai
Mirai 未来 - A powerful Minecraft Server Software coming from the future
Stars: ✭ 325 (+1525%)
Mutual labels:  patch
prop-types-definition
Patch for prop-types to get property type definition in runtime
Stars: ✭ 15 (-25%)
Mutual labels:  patch
plugin-flutter-patch
flutter patch generator in gradle
Stars: ✭ 22 (+10%)
Mutual labels:  patch
sane patch
Making monkey patches sane again
Stars: ✭ 63 (+215%)
Mutual labels:  patch
KanColle-English-Patch-KCCP
English Patch for the original KanColle browser game, to be used with KCCacheProxy. Translates most of the game into english.
Stars: ✭ 28 (+40%)
Mutual labels:  patch
intellij-diff-plugin
Syntax highlighting for .diff files and .patch files in IntelliJ IDEs
Stars: ✭ 17 (-15%)
Mutual labels:  patch
Smartappupdates
Android应用增量更新
Stars: ✭ 2,574 (+12770%)
Mutual labels:  bsdiff
FC2MPPatcher
A community-made utility for patching Far Cry 2 to yet again support multiplayer online.
Stars: ✭ 25 (+25%)
Mutual labels:  patch
bsdiff-cross-platform
android bsdiff and bspatch which includes java source code and native source code
Stars: ✭ 16 (-20%)
Mutual labels:  bsdiff
ctn
Unofficial Android patch for GTASA Android with various quality of life improvements
Stars: ✭ 44 (+120%)
Mutual labels:  patch
MacOS-All-In-One-Update-Script
Mac update shell script (Appstore, macOS, Homebrew and others)
Stars: ✭ 39 (+95%)
Mutual labels:  patch
bsdiff
Binary delta tools and library
Stars: ✭ 29 (+45%)
Mutual labels:  binary-diffing
duff
Pure OCaml implementation of libXdiff (Rabin's fingerprint)
Stars: ✭ 20 (+0%)
Mutual labels:  patch

bsdiff for Go

This wrapper implementation for Golang reuses the existing C version of bsdiff as provided by @mendsley and wraps it into a Go package, abstracting away all the cgo work that would need to be done otherwise.

Installation

The library and the helper binaries go-bsdiff and go-bspatch can be installed like this:

go get -v github.com/icedream/go-bsdiff/...

Usage in application code

For exact documentation of the library check out GoDoc.

Library functionality is provided both as a package bsdiff containing both methods Diff and Patch, or as subpackages diff and patch which each only link the wanted functionality.

Below example will generate a patch and apply it again in one go. This code is not safe against errors but it shows how to use the provided routines:

package main

import (
    "os"
    "github.com/icedream/go-bsdiff"
    // Or use the subpackages to only link what you need:
    //"github.com/icedream/go-bsdiff/diff"
    //"github.com/icedream/go-bsdiff/patch"
)

const (
    oldFilePath = "your_old_file.dat"
    newFilePath = "your_new_file.dat"
    patchFilePath = "the_generated.patch"
)

func generatePatch() error {
    oldFile, _ := os.Open(oldFilePath)
    defer oldFile.Close()
    newFile, _ := os.Open(newFilePath)
    defer newFile.Close()
    patchFile, _ := os.Create(patchFilePath)
    defer patchFile.Close()

    return bsdiff.Diff(oldFile, newFile, patchFile)
}

func applyPatch() error {
    oldFile, _ := os.Open(oldFilePath)
    defer oldFile.Close()
    newFile, _ := os.Create(newFilePath)
    defer newFile.Close()
    patchFile, _ := os.Open(patchFilePath)
    defer patchFile.Close()

    return bsdiff.Patch(oldFile, newFile, patchFile)
}

func main() {
    generatePatch()
    applyPatch()
}

Usage of the tools

The tools go-bsdiff and go-bspatch both provide a --help flag to print out all information but in their simplest form, they can be used like this:

# Creates a patch file $the_generated with differences from
# $your_old_file to $your_new_file.
go-bsdiff "$your_old_file" "$your_new_file" "$the_generated"

# Applies a patch file $the_generated on $your_old_file
# and saves the new file to $your_new_file.
go-bspatch "$your_old_file" "$your_new_file" "$the_generated"

Motivation

There is a Go implementation of an older version of bsdiff called binarydist. The original bsdiff tool has since been updated so patches generating using the original tool are no longer compatible with the Go implementation. I don't know what the changes between the versions are and unfortunately I don't have the time to search for these changes and port them over as a pull request, otherwise I'd have done that instead.

Additionally, @mendsley has already done the extra work of rewriting the code to be embeddable in any application code as a library. So why not make use of cgo, which I was going to look into in more detail at some point anyways?

License

Just like bsdiff, this project is licensed under the 2-clause BSD license (or Simplified BSD license). You can check LICENSE.txt for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].