blob: d14ae56c0ce04e7cb41faa3f693bd731ce1c64e8 (
about) (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package object
import (
"codeberg.org/lindenii/furgit/internal/objectheader"
"codeberg.org/lindenii/furgit/objecttype"
)
// SerializeWithoutHeader renders the raw blob body bytes.
func (blob *Blob) SerializeWithoutHeader() ([]byte, error) {
return append([]byte(nil), blob.Data...), nil
}
// SerializeWithHeader renders the raw object (header + body).
func (blob *Blob) SerializeWithHeader() ([]byte, error) {
body, err := blob.SerializeWithoutHeader()
if err != nil {
return nil, err
}
header, ok := objectheader.Encode(objecttype.TypeBlob, int64(len(body)))
if !ok {
return nil, ErrInvalidObject
}
raw := make([]byte, len(header)+len(body))
copy(raw, header)
copy(raw[len(header):], body)
return raw, nil
}
|