Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,45 @@ package main

import (
"fmt"

"github.com/balacode/go-delta"
)

func main() {
fmt.Print("Binary delta update demo:\n\n")

// The original data (20 bytes):
var source = []byte("quick brown fox, lazy dog, and five boxing wizards")
source := []byte("quick brown fox, lazy dog, and five boxing wizards")
fmt.Print("The original is:", "\n", string(source), "\n\n")

// The updated data containing the original and new content (82 bytes):
var target = []byte(
target := []byte(
"The quick brown fox jumps over the lazy dog. " +
"The five boxing wizards jump quickly.",
"The five boxing wizards jump quickly.",
)
fmt.Print("The update is:", "\n", string(target), "\n\n")

var dbytes []byte
{
// Use Make() to generate a compressed patch from source and target
var d = delta.Make(source, target)
// Convert the delta to a slice of bytes (e.g. for writing to a file)
dbytes = d.Bytes()
// Use Make() to generate a compressed patch from source and target
d := delta.Make(source, target)

// Convert the delta to a slice of bytes (e.g. for writing to a file)
dbytes = d.Bytes()
}

// Create a Delta from the byte slice
var d = delta.Load(dbytes)
d, err := delta.Load(dbytes)
if err != nil {
fmt.Println(err)
}

// Apply the patch to source to get the target
// The size of the patch is much shorter than target.
var target2, err = d.Apply(source)
target2, err := d.Apply(source)
if err != nil {
fmt.Println(err)
}
fmt.Print("Patched:", "\n", string(target2), "\n\n")
} // main
} //
```