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

Method FormatBinaryFragment

pkg/gitdiff/format.go:231–271  ·  view source on GitHub ↗
(f *BinaryFragment)

Source from the content-addressed store, hash-verified

229}
230
231func (fm *formatter) FormatBinaryFragment(f *BinaryFragment) {
232 const (
233 maxBytesPerLine = 52
234 )
235
236 switch f.Method {
237 case BinaryPatchDelta:
238 fm.WriteString("delta ")
239 case BinaryPatchLiteral:
240 fm.WriteString("literal ")
241 }
242 fm.Write(strconv.AppendInt(nil, f.Size, 10))
243 fm.WriteByte('\n')
244
245 data := deflateBinaryChunk(f.Data)
246 n := (len(data) / maxBytesPerLine) * maxBytesPerLine
247
248 buf := make([]byte, base85Len(maxBytesPerLine))
249 for i := 0; i < n; i += maxBytesPerLine {
250 base85Encode(buf, data[i:i+maxBytesPerLine])
251 fm.WriteByte('z')
252 fm.Write(buf)
253 fm.WriteByte('\n')
254 }
255 if remainder := len(data) - n; remainder > 0 {
256 buf = buf[0:base85Len(remainder)]
257
258 sizeChar := byte(remainder)
259 if remainder <= 26 {
260 sizeChar = 'A' + sizeChar - 1
261 } else {
262 sizeChar = 'a' + sizeChar - 27
263 }
264
265 base85Encode(buf, data[n:])
266 fm.WriteByte(sizeChar)
267 fm.Write(buf)
268 fm.WriteByte('\n')
269 }
270 fm.WriteByte('\n')
271}
272
273func deflateBinaryChunk(data []byte) []byte {
274 var b bytes.Buffer

Callers 2

FormatFileMethod · 0.95
StringMethod · 0.80

Calls 6

WriteStringMethod · 0.95
WriteMethod · 0.95
WriteByteMethod · 0.95
deflateBinaryChunkFunction · 0.85
base85LenFunction · 0.85
base85EncodeFunction · 0.70

Tested by

no test coverage detected