diff --git a/go.mod b/go.mod index c21283a..31f4d5e 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/src/tools/lib/zip.go b/src/tools/lib/zip.go index 4b80b90..c244b04 100644 --- a/src/tools/lib/zip.go +++ b/src/tools/lib/zip.go @@ -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 } diff --git a/src/tools/tools/packager.go b/src/tools/tools/packager.go index 41863b2..3e27a71 100644 --- a/src/tools/tools/packager.go +++ b/src/tools/tools/packager.go @@ -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, ) diff --git a/tools/tools-darwin b/tools/tools-darwin index a74f02b..001197b 100755 Binary files a/tools/tools-darwin and b/tools/tools-darwin differ diff --git a/tools/tools-linux b/tools/tools-linux index c59f7f8..87bb3bb 100755 Binary files a/tools/tools-linux and b/tools/tools-linux differ diff --git a/tools/tools.exe b/tools/tools.exe index de86c0f..e00d650 100644 Binary files a/tools/tools.exe and b/tools/tools.exe differ