aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/net.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-01-25 14:14:19 +0900
committerOphestra <cat@gensokyo.uk>2026-01-25 14:48:25 +0900
commit334578fddeda6c952b1c2e35829c91c9da72747e (patch)
tree2e3f65188ddbb600cf2f55913dd8f819b10672ea /internal/pkg/net.go
parent20790af71ec9a69a462ecaaa7fc308e3b685383d (diff)
internal/pkg: expose underlying reader
This will be fully implemented in httpArtifact in a future commit. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/net.go')
-rw-r--r--internal/pkg/net.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/internal/pkg/net.go b/internal/pkg/net.go
index c481b52e..8726fcac 100644
--- a/internal/pkg/net.go
+++ b/internal/pkg/net.go
@@ -1,6 +1,7 @@
package pkg
import (
+ "bytes"
"context"
"crypto/sha512"
"fmt"
@@ -34,13 +35,13 @@ type httpArtifact struct {
var _ KnownChecksum = new(httpArtifact)
var _ fmt.Stringer = new(httpArtifact)
-// NewHTTPGet returns a new [File] backed by the supplied client. A GET request
-// is set up for url. If c is nil, [http.DefaultClient] is used instead.
+// NewHTTPGet returns a new [FileArtifact] backed by the supplied client. A GET
+// request is set up for url. If c is nil, [http.DefaultClient] is used instead.
func NewHTTPGet(
c *http.Client,
url string,
checksum Checksum,
-) File {
+) FileArtifact {
if c == nil {
c = http.DefaultClient
}
@@ -103,15 +104,16 @@ func (a *httpArtifact) do(ctx context.Context) (data []byte, err error) {
// Cure completes the http request and returns the resulting response body read
// to EOF. Data does not interact with the filesystem.
-func (a *httpArtifact) Cure(ctx context.Context) (data []byte, err error) {
+func (a *httpArtifact) Cure(ctx context.Context) (r io.ReadCloser, err error) {
a.mu.Lock()
defer a.mu.Unlock()
if a.data != nil {
- // validated by cache or a previous call to Data
- return a.data, nil
+ // validated by cache or a previous call to Cure
+ return io.NopCloser(bytes.NewReader(a.data)), nil
}
+ var data []byte
if data, err = a.do(ctx); err != nil {
return
}
@@ -122,5 +124,6 @@ func (a *httpArtifact) Cure(ctx context.Context) (data []byte, err error) {
return nil, &ChecksumMismatchError{got, a.checksum}
}
a.data = data
+ r = io.NopCloser(bytes.NewReader(data))
return
}