From 15855e3249754ab7dc07183c9383f8a8e8c26af2 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Tue, 11 Nov 2025 00:00:00 +0000 Subject: Initial commit --- obj_blob.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 obj_blob.go (limited to 'obj_blob.go') 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 +} -- cgit v1.3.1-10-gc9f91