aboutsummaryrefslogtreecommitdiff
path: root/object/blob
diff options
context:
space:
mode:
Diffstat (limited to 'object/blob')
-rw-r--r--object/blob/append.go2
-rw-r--r--object/blob/clone.go11
-rw-r--r--object/blob/parse.go10
-rw-r--r--object/blob/type.go2
4 files changed, 21 insertions, 4 deletions
diff --git a/object/blob/append.go b/object/blob/append.go
index 378e4edb..8106f1c5 100644
--- a/object/blob/append.go
+++ b/object/blob/append.go
@@ -12,7 +12,7 @@ func (blob *Blob) AppendWithoutHeader(dst []byte) ([]byte, error) {
// AppendWithHeader renders the raw object (header + body).
func (blob *Blob) AppendWithHeader(dst []byte) ([]byte, error) {
- dst = header.Append(dst, typ.TypeBlob, uint64(len(blob.Data)))
+ dst = header.Append(dst, typ.Blob, len(blob.Data))
return blob.AppendWithoutHeader(dst)
}
diff --git a/object/blob/clone.go b/object/blob/clone.go
new file mode 100644
index 00000000..7106c3aa
--- /dev/null
+++ b/object/blob/clone.go
@@ -0,0 +1,11 @@
+package blob
+
+import "bytes"
+
+// Clone returns a deep copy of the blob
+// whose Data is independent of any memory the original may alias.
+//
+// Labels: Life-Independent.
+func (blob *Blob) Clone() *Blob {
+ return &Blob{Data: bytes.Clone(blob.Data)}
+}
diff --git a/object/blob/parse.go b/object/blob/parse.go
index c013af96..1796d42f 100644
--- a/object/blob/parse.go
+++ b/object/blob/parse.go
@@ -2,7 +2,13 @@ package blob
// Parse decodes a blob object body.
//
-// Labels: Life-Independent.
+// The returned blob aliases body:
+// its Data shares the same backing array,
+// so the blob inherits body's lifetime
+// and must not be mutated unless body may be.
+// Use [Blob.Clone] for an independent copy.
+//
+// Labels: Life-Parent, Mut-No.
func Parse(body []byte) (*Blob, error) {
- return &Blob{Data: append([]byte(nil), body...)}, nil
+ return &Blob{Data: body}, nil
}
diff --git a/object/blob/type.go b/object/blob/type.go
index 9669e038..c2d23e13 100644
--- a/object/blob/type.go
+++ b/object/blob/type.go
@@ -6,5 +6,5 @@ import "lindenii.org/go/furgit/object/typ"
func (blob *Blob) ObjectType() typ.Type {
_ = blob
- return typ.TypeBlob
+ return typ.Blob
}