MCPcopy Create free account
hub / github.com/antonmedv/gitmal / applyBinaryDeltaFragment

Function applyBinaryDeltaFragment

pkg/gitdiff/apply_binary.go:81–113  ·  view source on GitHub ↗
(dst io.Writer, src io.ReaderAt, frag []byte)

Source from the content-addressed store, hash-verified

79}
80
81func applyBinaryDeltaFragment(dst io.Writer, src io.ReaderAt, frag []byte) error {
82 srcSize, delta := readBinaryDeltaSize(frag)
83 if err := checkBinarySrcSize(src, srcSize); err != nil {
84 return err
85 }
86
87 dstSize, delta := readBinaryDeltaSize(delta)
88
89 for len(delta) > 0 {
90 op := delta[0]
91 if op == 0 {
92 return errors.New("invalid delta opcode 0")
93 }
94
95 var n int64
96 var err error
97 switch op & 0x80 {
98 case 0x80:
99 n, delta, err = applyBinaryDeltaCopy(dst, op, delta[1:], src)
100 case 0x00:
101 n, delta, err = applyBinaryDeltaAdd(dst, op, delta[1:])
102 }
103 if err != nil {
104 return err
105 }
106 dstSize -= n
107 }
108
109 if dstSize != 0 {
110 return errors.New("corrupt binary delta: insufficient or extra data")
111 }
112 return nil
113}
114
115// readBinaryDeltaSize reads a variable length size from a delta-encoded binary
116// fragment, returing the size and the unused data. Data is encoded as:

Callers 1

ApplyFragmentMethod · 0.85

Calls 5

readBinaryDeltaSizeFunction · 0.85
checkBinarySrcSizeFunction · 0.85
applyBinaryDeltaCopyFunction · 0.85
applyBinaryDeltaAddFunction · 0.85
NewMethod · 0.80

Tested by

no test coverage detected