internal/pkg: stream decompress artifact
All checks were successful
Test / Create distribution (push) Successful in 2m56s
Test / Sandbox (push) Successful in 6m55s
Test / Hakurei (push) Successful in 9m46s
Test / ShareFS (push) Successful in 10m21s
Test / Sandbox (race detector) (push) Successful in 10m44s
Test / Hakurei (race detector) (push) Successful in 14m34s
Test / Flake checks (push) Successful in 3m14s

The tarArtifact predates FileArtifact pipelining. This migrates decompression and buffering into a standalone artifact implementation.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-06-04 18:12:03 +09:00
parent 729be19af3
commit 76c1fb84c8
5 changed files with 229 additions and 4 deletions

View File

@@ -508,6 +508,8 @@ const (
KindExecNet
// KindFile is the kind of [Artifact] returned by [NewFile].
KindFile
// KindDecompress is the kind of [Artifact] returned by [NewDecompress].
KindDecompress
// _kindEnd is the total number of kinds and does not denote a kind.
_kindEnd
@@ -795,6 +797,38 @@ func (c *Cache) getReader(r io.Reader) *bufio.Reader {
// putReader adds br to brPool.
func (c *Cache) putReader(br *bufio.Reader) { c.brPool.Put(br) }
// bufioReadCloser is the concrete type of value returned by Cache.getReaderRC.
type bufioReadCloser struct {
// Saved close error.
closeErr error
// Synchronises calls to Close.
closeOnce sync.Once
// For backing freelist.
c *Cache
// Underlying reader.
r io.ReadCloser
// Allocated from c.
*bufio.Reader
}
// Close closes the underlying reader, saves its return value, and returns the
// [bufio.Reader] instance to the backing [Cache].
func (brc *bufioReadCloser) Close() error {
brc.closeOnce.Do(func() {
br := brc.Reader
brc.Reader = nil
brc.c.putReader(br)
brc.closeErr = brc.r.Close()
})
return brc.closeErr
}
// getReaderRC is like getReader, but returns an [io.ReadCloser].
func (c *Cache) getReaderRC(r io.ReadCloser) io.ReadCloser {
return &bufioReadCloser{c: c, r: r, Reader: c.getReader(r)}
}
// getWriter is like [bufio.NewWriter] but for bwPool.
func (c *Cache) getWriter(w io.Writer) *bufio.Writer {
bw := c.bwPool.Get().(*bufio.Writer)