From be69a505926451bf10450ac68d40265a6f43e150 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Sun, 25 Oct 2015 12:34:25 +0100 Subject: formats/packfile: new reader API (wip) --- formats/packfile/delta.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'formats/packfile/delta.go') diff --git a/formats/packfile/delta.go b/formats/packfile/delta.go index 86b556f..30703eb 100644 --- a/formats/packfile/delta.go +++ b/formats/packfile/delta.go @@ -1,5 +1,7 @@ package packfile +import "io" + const delta_size_min = 4 func deltaHeaderSize(b []byte) (uint, []byte) { @@ -91,3 +93,24 @@ func PatchDelta(src, delta []byte) []byte { } return dest } + +func decodeOffset(src io.ByteReader, steps int) (int, error) { + b, err := src.ReadByte() + if err != nil { + return 0, err + } + var offset = int(b & 0x7f) + for (b & 0x80) != 0 { + offset++ // WHY? + b, err = src.ReadByte() + if err != nil { + return 0, err + } + + offset = (offset << 7) + int(b&0x7f) + } + + // offset needs to be aware of the bytes we read for `o.typ` and `o.size` + offset += steps + return -offset, nil +} -- cgit