internal/pkg: streaming archive reader/writer
All checks were successful
Test / Create distribution (push) Successful in 1m5s
Test / Sandbox (push) Successful in 2m49s
Test / Hakurei (push) Successful in 3m53s
Test / ShareFS (push) Successful in 3m51s
Test / Sandbox (race detector) (push) Successful in 5m35s
Test / Hakurei (race detector) (push) Successful in 6m32s
Test / Flake checks (push) Successful in 1m15s

This is much more robust and efficient than the simple buffering implementation for larger files. Allocations happen almost exclusively in WalkDir.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-06-03 15:51:43 +09:00
parent 83498b5a8a
commit 42cea1e7c6
7 changed files with 492 additions and 343 deletions

View File

@@ -26,7 +26,17 @@ func padSize[T int | int64](sz T) T {
return (wordSize - (sz)%wordSize) % wordSize
}
// WriteReport writes a report of all available [PArtifact] to w.
// countWriter records total amount of data written.
type countWriter uint64
// Write records the size of p.
func (w *countWriter) Write(p []byte) (n int, err error) {
n = len(p)
*w += countWriter(n)
return
}
// WriteReport writes a report of all available [Artifact] to w.
func WriteReport(msg message.Msg, w io.Writer, c *pkg.Cache) error {
var (
zero [wordSize]byte
@@ -90,12 +100,12 @@ func WriteReport(msg message.Msg, w io.Writer, c *pkg.Cache) error {
}
// existence of status implies cured artifact
var n int
var n countWriter
if pathname, _, err := c.Cure(a); err != nil {
return err
} else if n, err = pkg.Flatten(
} else if err = pkg.Write(
os.DirFS(pathname.String()), ".",
io.Discard,
&n,
); err != nil {
return err
}