build: fixed packaging tool reporting total instead of compressed size
This commit is contained in:
3
go.mod
3
go.mod
@@ -3,8 +3,7 @@ module uosc/bins
|
|||||||
go 1.21.3
|
go 1.21.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/atotto/clipboard v0.1.4
|
||||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
|
||||||
k8s.io/apimachinery v0.28.3
|
k8s.io/apimachinery v0.28.3
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/atotto/clipboard v0.1.4 // indirect
|
|
||||||
|
@@ -8,6 +8,19 @@ import (
|
|||||||
"path/filepath"
|
"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:
|
`files` format:
|
||||||
|
|
||||||
@@ -39,7 +52,8 @@ func ZipFilesWithHeaders(files map[string]string, outputFile string, headerMod H
|
|||||||
return ZipStats{}, err
|
return ZipStats{}, err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
zw := zip.NewWriter(f)
|
countedF := &CountingWriter{writer: f}
|
||||||
|
zw := zip.NewWriter(countedF)
|
||||||
defer zw.Close()
|
defer zw.Close()
|
||||||
|
|
||||||
var filesNum, bytes int64
|
var filesNum, bytes int64
|
||||||
@@ -127,8 +141,9 @@ func ZipFilesWithHeaders(files map[string]string, outputFile string, headerMod H
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ZipStats{
|
return ZipStats{
|
||||||
FilesNum: filesNum,
|
FilesNum: filesNum,
|
||||||
Bytes: bytes,
|
TotalBytes: bytes,
|
||||||
|
CompressedBytes: countedF.written,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,6 +151,7 @@ func ZipFilesWithHeaders(files map[string]string, outputFile string, headerMod H
|
|||||||
type HeaderModFn func(header *zip.FileHeader) *zip.FileHeader
|
type HeaderModFn func(header *zip.FileHeader) *zip.FileHeader
|
||||||
|
|
||||||
type ZipStats struct {
|
type ZipStats struct {
|
||||||
FilesNum int64
|
FilesNum int64
|
||||||
Bytes int64
|
TotalBytes int64
|
||||||
|
CompressedBytes int64
|
||||||
}
|
}
|
||||||
|
@@ -58,7 +58,7 @@ func Packager(args []string) {
|
|||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"Packaging into: %s\n- uosc.zip: %.2f MB, %d files\n- uosc.conf: %.1f KB",
|
"Packaging into: %s\n- uosc.zip: %.2f MB, %d files\n- uosc.conf: %.1f KB",
|
||||||
filepath.ToSlash(must(filepath.Rel(cwd, releaseRoot)))+"/",
|
filepath.ToSlash(must(filepath.Rel(cwd, releaseRoot)))+"/",
|
||||||
float64(stats.Bytes)/1024/1024,
|
float64(stats.CompressedBytes)/1024/1024,
|
||||||
stats.FilesNum,
|
stats.FilesNum,
|
||||||
float64(confSize)/1024,
|
float64(confSize)/1024,
|
||||||
)
|
)
|
||||||
|
Binary file not shown.
Binary file not shown.
BIN
tools/tools.exe
BIN
tools/tools.exe
Binary file not shown.
Reference in New Issue
Block a user