From 42cea1e7c6d1ea0658e6b4d2a1f12f98b9c0dd22 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Wed, 3 Jun 2026 15:51:43 +0900 Subject: internal/pkg: streaming archive reader/writer 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 --- internal/rosa/report.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'internal/rosa/report.go') diff --git a/internal/rosa/report.go b/internal/rosa/report.go index 29a74233..54f60fb3 100644 --- a/internal/rosa/report.go +++ b/internal/rosa/report.go @@ -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 } -- cgit v1.3.1