delta

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDelta = errors.New("delta: invalid format")
	ErrChecksum     = errors.New("delta: checksum mismatch")
)

Functions

func Apply

func Apply(source, delta []byte) (result []byte, err error)

Apply reconstructs target data from source and delta. Variable naming follows fossil/src/delta.c for cross-reference:

cnt = count, offset = source offset, cmd = command byte

func Checksum

func Checksum(data []byte) uint32

Checksum computes Fossil's delta checksum, matching delta.c's checksum(). Sum of 4-byte big-endian words, with trailing bytes in big-endian position.

func Create

func Create(source, target []byte) (result []byte)

Create generates a delta that transforms source into target. Variable naming follows fossil/src/delta.c for cross-reference:

nHash = NHASH, ei = entry index, ml = match length, tPos = target position, sOff = source offset
Example
package main

import (
	"fmt"

	"github.com/danmestas/libfossil/internal/delta"
)

func main() {
	source := []byte("the quick brown fox jumps over the lazy dog\n")
	target := []byte("the quick brown fox leaps over the lazy dog\n")

	d := delta.Create(source, target)

	// Delta is smaller than storing the full target.
	fmt.Printf("delta smaller: %v\n", len(d) < len(target))

	// Apply reconstructs the target from source + delta.
	reconstructed, err := delta.Apply(source, d)
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	fmt.Print(string(reconstructed))
}
Output:
delta smaller: true
the quick brown fox leaps over the lazy dog

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL