Fast implementation of Git in pure Go
1package object
2
3import (
4 "errors"
5
6 "codeberg.org/lindenii/furgit/objectheader"
7 "codeberg.org/lindenii/furgit/objecttype"
8)
9
10// SerializeWithoutHeader renders the raw blob body bytes.
11func (blob *Blob) SerializeWithoutHeader() ([]byte, error) {
12 return append([]byte(nil), blob.Data...), nil
13}
14
15// SerializeWithHeader renders the raw object (header + body).
16func (blob *Blob) SerializeWithHeader() ([]byte, error) {
17 body, err := blob.SerializeWithoutHeader()
18 if err != nil {
19 return nil, err
20 }
21
22 header, ok := objectheader.Encode(objecttype.TypeBlob, int64(len(body)))
23 if !ok {
24 return nil, errors.New("object: blob: failed to encode object header")
25 }
26
27 raw := make([]byte, len(header)+len(body))
28 copy(raw, header)
29 copy(raw[len(header):], body)
30
31 return raw, nil
32}