https://github.com/kuba--/diff
delta encoding package
https://github.com/kuba--/diff
delta-compression
Last synced: about 2 months ago
JSON representation
delta encoding package
- Host: GitHub
- URL: https://github.com/kuba--/diff
- Owner: kuba--
- Created: 2021-09-09T20:26:19.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-11T18:35:13.000Z (about 1 year ago)
- Last Synced: 2025-01-15T16:54:51.380Z (4 months ago)
- Topics: delta-compression
- Language: Go
- Homepage:
- Size: 29.3 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# diff
A delta encoding library heavily inspired by [rdiff](https://linux.die.net/man/1/rdiff).
```
signature(basis-file) -> sig-filedelta(sig-file, new-file) -> delta-file
patch(basis-file, delta-file) -> recreated-file
```The idea of _rolling checksum_ algorithm (_rollsum_) was taken from [librsync](https://github.com/librsync/librsync).
### API & File spec.
```go
package diffvar (
ByteOrder = binary.BigEndian
NewHash = md5.New
)
```- Signature
```go
type (
Signature struct {
signatureHeader
signatureChecksum
}signatureHeader struct {
BlockSize uint32
StrongSize byte
}signatureChecksum struct {
weak map[uint32]int
strong [][]byte
}
)diff.WriteSignature(basisReader io.Reader, signatureWriter io.Writer, blockSize uint32, strongSize byte) (*diff.Signature, error)
diff.ReadSignature(signatureReader io.Reader) (*diff.Signature, error)func (sig *Signature) Lookup(weak uint32) (strong []byte, offset uint64, blockSize uint32, ok bool)
```File spec.:
```
// header
{block size: 4 bytes, strong checksum size: 1 byte}
// checksum
{weak checksum: 4 bytes, strong checksum: StrongSize bytes}
{weak checksum: 4 bytes, strong checksum: StrongSize bytes}
...
{weak checksum: 4 bytes, strong checksum: StrongSize bytes}
```---
- Delta
```go
const (
FromOld = byte(0x0)
FromNew = byte(0x1)
)type (
Delta = []*DeltaInstructionDeltaInstruction struct {
DeltaInstructionHeader
Data []byte
}DeltaInstructionHeader struct {
From byte
Offset uint64
Size uint64
}
)diff.WriteDelta(signature *diff.Signature, newReader io.Reader, deltaWriter io.Writer) error
diff.ReadDelta(r io.Reader) (delta diff.Delta, err error)
diff.ReadDeltaInstructionHeader(r io.Reader) (header diff.DeltaInstructionHeader, err error)
```File spec.:
```
// instruction
{from: 1 byte, offset: 8 bytes, size: 8 bytes}
// data
...// instruction
{from: 1 byte, offset: 8 bytes, size: 8 bytes}
// data
...
```---
- Patch
```go
diff.Patch(basisReaderSeeker io.ReadSeeker, deltaReader io.Reader, newWriter io.Writer) error
```### Usage
```
go build ./cmd/signature
./signature [-b block size] [-s strong size] old-file signature-filego build ./cmd/delta
./delta signature-file new-file delta-filego build ./cmd/patch
./patch old-file delta-file new-file
```