Skip to content

Commit

Permalink
examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gabstv committed Feb 25, 2019
1 parent aedc78a commit e746171
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ Pure Go implementation of [bsdiff](http://www.daemonology.net/bsdiff/) 4.

bsdiff and bspatch are tools for building and applying patches to binary files. By using suffix sorting (specifically, Larsson and Sadakane's [qsufsort](http://www.larsson.dogma.net/ssrev-tr.pdf)) and taking advantage of how executable files change.

The package can be used as a library (pkg/bsdiff pkg/bspatch) or as a cli program (cmd/bsdiff cmd/bspatch).

## As a library

### Bsdiff Bytes
```Go
package main

import (
"fmt"
"bytes"

"github.com/gabstv/go-bsdiff/pkg/bsdiff"
"github.com/gabstv/go-bsdiff/pkg/bspatch"
)

func main(){
Expand All @@ -20,5 +27,39 @@ func main(){
panic(err)
}
fmt.Println(patch)
newfile2, err := bspatch.Bytes(oldfile, patch)
if err != nil {
panic(err)
}
if !bytes.Equal(newfile, newfile2) {
panic()
}
}
```
### Bsdiff Reader
```Go
package main

import (
"fmt"
"bytes"

"github.com/gabstv/go-bsdiff/pkg/bsdiff"
"github.com/gabstv/go-bsdiff/pkg/bspatch"
)

func main(){
oldrdr := bytes.NewReader([]byte{0xfa, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff})
newrdr := bytes.NewReader([]byte{0xfa, 0xdd, 0x00, 0x00, 0x00, 0xee, 0xee, 0x00, 0x00, 0xff, 0xfe, 0xfe})
patch := new(bytes.Buffer)
if err := bsdiff.Reader(oldrdr, newrdr, patch); err != nil {
panic(err)
}
newpatchedf := new(bytes.Buffer)
oldrdr.Seek(0, 0)
if err := bspatch.Reader(oldrdr, newpatchedf, patch); err != nil {
panic(err)
}
fmt.Println(newpatchedf.Bytes())
}
```

0 comments on commit e746171

Please sign in to comment.