diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-01-07 00:39:29 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-01-07 00:39:29 +0900 |
| commit | 3a21ba1bcadd33a32a011329362d901374716626 (patch) | |
| tree | e1b840ad264f60d728d097a5ef7cb82934986838 /internal/pkg/file.go | |
| parent | 45301559bf4df313fef6894ec900e8a618339a79 (diff) | |
internal/pkg: implement file artifact
This is an Artifact implementing File, backed by a constant, caller-supplied byte slice.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/file.go')
| -rw-r--r-- | internal/pkg/file.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/pkg/file.go b/internal/pkg/file.go new file mode 100644 index 00000000..d7ac933f --- /dev/null +++ b/internal/pkg/file.go @@ -0,0 +1,40 @@ +package pkg + +import ( + "crypto/sha512" + "syscall" +) + +// A fileArtifact is an [Artifact] that cures into data known ahead of time. +type fileArtifact []byte + +var _ KnownChecksum = fileArtifact{} + +// NewFile returns a [File] that cures into a caller-supplied byte slice. +// +// Caller must not modify data after NewBin returns. +func NewFile(data []byte) File { return fileArtifact(data) } + +// Kind returns the hardcoded [Kind] constant. +func (a fileArtifact) Kind() Kind { return KindFile } + +// Params returns the result of Data. +func (a fileArtifact) Params() []byte { return a } + +// Dependencies returns a nil slice. +func (a fileArtifact) Dependencies() []Artifact { return nil } + +// Checksum computes and returns the checksum of caller-supplied data. +func (a fileArtifact) Checksum() Checksum { + h := sha512.New384() + h.Write(a) + return Checksum(h.Sum(nil)) +} + +// Data returns the caller-supplied data. +func (a fileArtifact) Data() ([]byte, error) { return a, nil } + +// Cure returns syscall.ENOTSUP. Callers should use Data instead. +func (a fileArtifact) Cure(*CureContext) (err error) { + return syscall.ENOTSUP +} |
