diff options
| author | 2026-03-06 18:38:44 +0800 | |
|---|---|---|
| committer | 2026-03-06 18:58:30 +0800 | |
| commit | f2922155de01b734e3e8b3f50be8f263ec13cacd (patch) | |
| tree | 6dcfcf5689e63eea09314dce543e1de26cab89fe /object | |
| parent | internal/compress: Format (diff) | |
| signature | No signature | |
*: Lint v0.1.68
Diffstat (limited to 'object')
| -rw-r--r-- | object/parse.go | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/object/parse.go b/object/parse.go index 1b15f377..9afe5cb8 100644 --- a/object/parse.go +++ b/object/parse.go @@ -8,7 +8,26 @@ import ( "codeberg.org/lindenii/furgit/objecttype" ) +// ParseObjectWithHeader parses a loose object in "type size\x00body" format. +// +//nolint:ireturn +func ParseObjectWithHeader(raw []byte, algo objectid.Algorithm) (Object, error) { + ty, size, headerLen, ok := objectheader.Parse(raw) + if !ok { + return nil, fmt.Errorf("object: malformed object header") + } + + body := raw[headerLen:] + if int64(len(body)) != size { + return nil, fmt.Errorf("object: size mismatch: header says %d bytes, body has %d", size, len(body)) + } + + return ParseObjectWithoutHeader(ty, body, algo) +} + // ParseObjectWithoutHeader parses a typed object body. +// +//nolint:ireturn func ParseObjectWithoutHeader(ty objecttype.Type, body []byte, algo objectid.Algorithm) (Object, error) { switch ty { case objecttype.TypeBlob: @@ -25,18 +44,3 @@ func ParseObjectWithoutHeader(ty objecttype.Type, body []byte, algo objectid.Alg return nil, fmt.Errorf("object: unsupported object type %d", ty) } } - -// ParseObjectWithHeader parses a loose object in "type size\\x00body" format. -func ParseObjectWithHeader(raw []byte, algo objectid.Algorithm) (Object, error) { - ty, size, headerLen, ok := objectheader.Parse(raw) - if !ok { - return nil, fmt.Errorf("object: malformed object header") - } - - body := raw[headerLen:] - if int64(len(body)) != size { - return nil, fmt.Errorf("object: size mismatch: header says %d bytes, body has %d", size, len(body)) - } - - return ParseObjectWithoutHeader(ty, body, algo) -} |
