aboutsummaryrefslogtreecommitdiff
path: root/object/parse.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-06 18:38:44 +0800
committerGravatar Runxi Yu2026-03-06 18:58:30 +0800
commitf2922155de01b734e3e8b3f50be8f263ec13cacd (patch)
tree6dcfcf5689e63eea09314dce543e1de26cab89fe /object/parse.go
parentinternal/compress: Format (diff)
signatureNo signature
*: Lint v0.1.68
Diffstat (limited to 'object/parse.go')
-rw-r--r--object/parse.go34
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)
-}