aboutsummaryrefslogtreecommitdiff
path: root/obj_blob.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2025-11-11 00:00:00 +0000
committerGravatar Runxi Yu2025-11-13 00:00:00 +0000
commit15855e3249754ab7dc07183c9383f8a8e8c26af2 (patch)
tree83b32bdd63f7e672152f07d89268e9b268d1f3f5 /obj_blob.go
signature
Initial commit
Diffstat (limited to 'obj_blob.go')
-rw-r--r--obj_blob.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/obj_blob.go b/obj_blob.go
new file mode 100644
index 00000000..eda0ca5f
--- /dev/null
+++ b/obj_blob.go
@@ -0,0 +1,33 @@
+package furgit
+
+// Blob represents the contents of a Git blob.
+type Blob struct {
+ objectBase
+
+ Data []byte
+}
+
+// ObjType allows Blob to satisfy the Object interface.
+func (*Blob) ObjType() ObjType {
+ return ObjBlob
+}
+
+func parseBlob(id Hash, body []byte) (*Blob, error) {
+ data := append([]byte(nil), body...)
+ return &Blob{
+ objectBase: objectBase{Hash: id},
+ Data: data,
+ }, nil
+}
+
+// Serialize renders the full "blob size\\0body" representation.
+func (b *Blob) Serialize() ([]byte, error) {
+ header, err := headerForType(ObjBlob, b.Data)
+ if err != nil {
+ return nil, err
+ }
+ raw := make([]byte, len(header)+len(b.Data))
+ copy(raw, header)
+ copy(raw[len(header):], b.Data)
+ return raw, nil
+}