go-bsdiff/cmd/go-bspatch/main.go

44 lines
848 B
Go
Raw Normal View History

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()
2017-02-22 16:55:32 +00:00
argNew = cli.Arg("new", "Where the new file will be written to.").Required().String()
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:]))
oldFile, err := os.Open(*argOld)
must(err)
defer oldFile.Close()
2017-02-22 16:55:32 +00:00
newFile, err := os.Create(*argNew)
must(err)
defer newFile.Close()
patchFile, err := os.Open(*argPatch)
must(err)
defer patchFile.Close()
must(patch.Patch(oldFile, newFile, patchFile))
}