Implement general utility binaries go-bsdiff and go-bspatch.
parent
419ea010c2
commit
9aa388006e
|
@ -1,31 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/icedream/go-bsdiff"
|
|
||||||
)
|
|
||||||
|
|
||||||
func must(err error) {
|
|
||||||
if err == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
oldFile, err := os.Open("test.txt")
|
|
||||||
must(err)
|
|
||||||
|
|
||||||
newFile, err := os.Open("test_new.txt")
|
|
||||||
must(err)
|
|
||||||
|
|
||||||
patchFile, err := os.Create("test.patch")
|
|
||||||
must(err)
|
|
||||||
|
|
||||||
must(bsdiff.Diff(oldFile, newFile, patchFile))
|
|
||||||
|
|
||||||
log.Println("Done.")
|
|
||||||
}
|
|
Binary file not shown.
|
@ -0,0 +1,42 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/icedream/go-bsdiff/patch"
|
||||||
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
cli = kingpin.New("go-bspatch", "Applies binary patches generated using the bsdiff algorithm.")
|
||||||
|
|
||||||
|
argOld = cli.Arg("old", "The old file.").Required().ExistingFile()
|
||||||
|
argNew = cli.Arg("new", "Where the new file will be written to.").Required().File()
|
||||||
|
argPatch = cli.Arg("patch", "The patch file.").Required().ExistingFile()
|
||||||
|
)
|
||||||
|
|
||||||
|
func must(err error) {
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
kingpin.MustParse(cli.Parse(os.Args[1:]))
|
||||||
|
|
||||||
|
newFile := *argNew
|
||||||
|
defer newFile.Close()
|
||||||
|
|
||||||
|
oldFile, err := os.Open(*argOld)
|
||||||
|
must(err)
|
||||||
|
defer oldFile.Close()
|
||||||
|
|
||||||
|
patchFile, err := os.Open(*argPatch)
|
||||||
|
must(err)
|
||||||
|
defer patchFile.Close()
|
||||||
|
|
||||||
|
must(patch.Patch(oldFile, newFile, patchFile))
|
||||||
|
}
|
Binary file not shown.
|
@ -0,0 +1,42 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/icedream/go-bsdiff/diff"
|
||||||
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
cli = kingpin.New("go-bsdiff", "Generates binary patches.")
|
||||||
|
|
||||||
|
argOld = cli.Arg("old", "The old file.").Required().ExistingFile()
|
||||||
|
argNew = cli.Arg("new", "The new file.").Required().ExistingFile()
|
||||||
|
argPatch = cli.Arg("patch", "Where to output the patch file.").Required().File()
|
||||||
|
)
|
||||||
|
|
||||||
|
func must(err error) {
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
kingpin.MustParse(cli.Parse(os.Args[1:]))
|
||||||
|
|
||||||
|
patchFile := *argPatch
|
||||||
|
defer patchFile.Close()
|
||||||
|
|
||||||
|
oldFile, err := os.Open(*argOld)
|
||||||
|
must(err)
|
||||||
|
defer oldFile.Close()
|
||||||
|
|
||||||
|
newFile, err := os.Open(*argNew)
|
||||||
|
must(err)
|
||||||
|
defer newFile.Close()
|
||||||
|
|
||||||
|
must(diff.Diff(oldFile, newFile, patchFile))
|
||||||
|
}
|
Loading…
Reference in New Issue