Add raw subpackage.
parent
0a7b37e323
commit
e11f761ece
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
/*
|
||||
This subpackage directly exposes bsdiff functionality without any
|
||||
file format or compression code wrapped around it.
|
||||
*/
|
||||
package raw
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue