aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/file.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-02-04 14:41:18 +0900
committerOphestra <cat@gensokyo.uk>2026-02-05 08:24:09 +0900
commite0c720681bbce364910df241658dc987851e579a (patch)
treebdbfbd67f26d562e8f1b2b2980a4bde6a10c94cc /internal/pkg/file.go
parentf982b13a59a59e22d1ff3fdf791c1aa86b9420df (diff)
internal/pkg: standardise artifact IR
This should hopefully provide good separation between the artifact curing backend implementation and the (still work in progress) language. Making the IR parseable also guarantees uniqueness of the representation. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/file.go')
-rw-r--r--internal/pkg/file.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/internal/pkg/file.go b/internal/pkg/file.go
index c2093d6b..149ca817 100644
--- a/internal/pkg/file.go
+++ b/internal/pkg/file.go
@@ -25,6 +25,12 @@ var _ KnownChecksum = new(fileArtifactNamed)
// String returns the caller-supplied reporting name.
func (a *fileArtifactNamed) String() string { return a.name }
+// Params writes the caller-supplied reporting name and the file body.
+func (a *fileArtifactNamed) Params(ctx *IContext) {
+ ctx.WriteString(a.name)
+ ctx.Write(a.fileArtifact)
+}
+
// NewFile returns a [FileArtifact] that cures into a caller-supplied byte slice.
//
// Caller must not modify data after NewFile returns.
@@ -39,8 +45,22 @@ func NewFile(name string, data []byte) FileArtifact {
// Kind returns the hardcoded [Kind] constant.
func (*fileArtifact) Kind() Kind { return KindFile }
-// Params writes the result of Cure.
-func (a *fileArtifact) Params(ctx *IContext) { ctx.GetHash().Write(*a) }
+// Params writes an empty string and the file body.
+func (a *fileArtifact) Params(ctx *IContext) {
+ ctx.WriteString("")
+ ctx.Write(*a)
+}
+
+func init() {
+ register(KindFile, func(r *IRReader) Artifact {
+ name := r.ReadString()
+ data := r.ReadStringBytes()
+ if _, ok := r.Finalise(); !ok {
+ panic(ErrExpectedChecksum)
+ }
+ return NewFile(name, data)
+ })
+}
// Dependencies returns a nil slice.
func (*fileArtifact) Dependencies() []Artifact { return nil }