internal/pkg: expose underlying reader
All checks were successful
Test / Create distribution (push) Successful in 49s
Test / Sandbox (push) Successful in 2m42s
Test / ShareFS (push) Successful in 3m57s
Test / Hpkg (push) Successful in 4m37s
Test / Sandbox (race detector) (push) Successful in 5m0s
Test / Hakurei (race detector) (push) Successful in 5m54s
Test / Hakurei (push) Successful in 2m41s
Test / Flake checks (push) Successful in 1m41s

This will be fully implemented in httpArtifact in a future commit.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-01-25 14:14:19 +09:00
parent 20790af71e
commit 334578fdde
8 changed files with 157 additions and 93 deletions

View File

@@ -1,9 +1,11 @@
package pkg
import (
"bytes"
"context"
"crypto/sha512"
"fmt"
"io"
)
// A fileArtifact is an [Artifact] that cures into data known ahead of time.
@@ -24,10 +26,10 @@ var _ KnownChecksum = new(fileArtifactNamed)
// String returns the caller-supplied reporting name.
func (a *fileArtifactNamed) String() string { return a.name }
// NewFile returns a [File] that cures into a caller-supplied byte slice.
// NewFile returns a [FileArtifact] that cures into a caller-supplied byte slice.
//
// Caller must not modify data after NewFile returns.
func NewFile(name string, data []byte) File {
func NewFile(name string, data []byte) FileArtifact {
f := fileArtifact(data)
if name != "" {
return &fileArtifactNamed{f, name}
@@ -52,4 +54,6 @@ func (a *fileArtifact) Checksum() Checksum {
}
// Cure returns the caller-supplied data.
func (a *fileArtifact) Cure(context.Context) ([]byte, error) { return *a, nil }
func (a *fileArtifact) Cure(context.Context) (io.ReadCloser, error) {
return io.NopCloser(bytes.NewReader(*a)), nil
}