Add raw subpackage.

master
Icedream 2017-02-26 02:23:44 +01:00
parent 0a7b37e323
commit e11f761ece
Signed by: icedream
GPG Key ID: 1573F6D8EFE4D0CF
3 changed files with 64 additions and 0 deletions

29
raw/diff/diff.go Normal file
View File

@ -0,0 +1,29 @@
package diff
import (
"io"
"io/ioutil"
"github.com/icedream/go-bsdiff/internal/native"
)
/*
Diff generates a raw patch from old content that will be read in completely from
oldReader and new content that will be read in completely from newReader and
saves that patch to patchWriter.
It may be helpful to save away the new content size along with the actual
patch as it will be needed in order to reuse the patch.
*/
func Diff(oldReader, newReader io.Reader, patchWriter io.Writer) (err error) {
oldBytes, err := ioutil.ReadAll(oldReader)
if err != nil {
return
}
newBytes, err := ioutil.ReadAll(newReader)
if err != nil {
return
}
return native.Diff(oldBytes, newBytes, patchWriter)
}

5
raw/doc.go Normal file
View File

@ -0,0 +1,5 @@
/*
This subpackage directly exposes bsdiff functionality without any
file format or compression code wrapped around it.
*/
package raw

30
raw/patch/patch.go Normal file
View File

@ -0,0 +1,30 @@
package patch
import (
"io"
"io/ioutil"
"github.com/icedream/go-bsdiff/internal/native"
)
/*
Patch reads a raw patch from patchReader and applies it on top of the old
content which will be read from oldReader, saving the resulting new content to
newWriter.
newSize needs to be exactly the size of the new file that should be generated
from the patch.
*/
func Patch(oldReader io.Reader, newWriter io.Writer, patchReader io.Reader, newSize uint64) (err error) {
oldBytes, err := ioutil.ReadAll(oldReader)
if err != nil {
return
}
newBytes := make([]byte, newSize)
err = native.Patch(oldBytes, newBytes, oldReader)
newWriter.Write(newBytes)
return
}