build: fixed packaging tool reporting total instead of compressed size

This commit is contained in:
tomasklaen
2023-11-04 18:41:26 +01:00
parent a8f040af0d
commit 8d2dfc4b00
6 changed files with 23 additions and 8 deletions

3
go.mod
View File

@@ -3,8 +3,7 @@ module uosc/bins
go 1.21.3
require (
github.com/atotto/clipboard v0.1.4
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
k8s.io/apimachinery v0.28.3
)
require github.com/atotto/clipboard v0.1.4 // indirect

View File

@@ -8,6 +8,19 @@ import (
"path/filepath"
)
// CountingWriter wraps an io.Writer and counts the number of bytes written.
type CountingWriter struct {
written int64
writer io.Writer
}
// Write writes bytes and counts them.
func (cw *CountingWriter) Write(p []byte) (int, error) {
n, err := cw.writer.Write(p)
cw.written += int64(n)
return n, err
}
/*
`files` format:
@@ -39,7 +52,8 @@ func ZipFilesWithHeaders(files map[string]string, outputFile string, headerMod H
return ZipStats{}, err
}
defer f.Close()
zw := zip.NewWriter(f)
countedF := &CountingWriter{writer: f}
zw := zip.NewWriter(countedF)
defer zw.Close()
var filesNum, bytes int64
@@ -127,8 +141,9 @@ func ZipFilesWithHeaders(files map[string]string, outputFile string, headerMod H
}
return ZipStats{
FilesNum: filesNum,
Bytes: bytes,
FilesNum: filesNum,
TotalBytes: bytes,
CompressedBytes: countedF.written,
}, nil
}
@@ -136,6 +151,7 @@ func ZipFilesWithHeaders(files map[string]string, outputFile string, headerMod H
type HeaderModFn func(header *zip.FileHeader) *zip.FileHeader
type ZipStats struct {
FilesNum int64
Bytes int64
FilesNum int64
TotalBytes int64
CompressedBytes int64
}

View File

@@ -58,7 +58,7 @@ func Packager(args []string) {
fmt.Printf(
"Packaging into: %s\n- uosc.zip: %.2f MB, %d files\n- uosc.conf: %.1f KB",
filepath.ToSlash(must(filepath.Rel(cwd, releaseRoot)))+"/",
float64(stats.Bytes)/1024/1024,
float64(stats.CompressedBytes)/1024/1024,
stats.FilesNum,
float64(confSize)/1024,
)

Binary file not shown.

Binary file not shown.

Binary file not shown.