Skip to content

Commit 593ee2a

Browse files
committed
Address code review feedback: improve robustness
- Use CustomSize for formatSize to avoid dependency on HumanSize format - Improve regex to match only valid numbers (integer or float) - Remove unused strings import from safetensors package
1 parent ef671b0 commit 593ee2a

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

pkg/distribution/internal/gguf/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ func configFromFile(path string) types.Config {
6565
}
6666

6767
var (
68-
// spaceBeforeUnitRegex matches one or more spaces between a number/decimal and a letter (unit)
68+
// spaceBeforeUnitRegex matches one or more spaces between a valid number and a letter (unit)
6969
// Used to remove spaces between numbers and units (e.g., "16.78 M" -> "16.78M")
70-
// Pattern: digits/decimals, then whitespace, then letters (unit)
71-
spaceBeforeUnitRegex = regexp.MustCompile(`([0-9.]+)\s+([A-Za-z]+)`)
70+
// Pattern: integer or decimal number, then whitespace, then letters (unit)
71+
spaceBeforeUnitRegex = regexp.MustCompile(`([0-9]+(?:\.[0-9]+)?)\s+([A-Za-z]+)`)
7272
)
7373

7474
// normalizeUnitString removes spaces between numbers and units for consistent formatting

pkg/distribution/internal/safetensors/metadata.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"io"
88
"os"
9-
"strings"
109

1110
"github.com/docker/go-units"
1211
)
@@ -193,7 +192,5 @@ func formatParameters(params int64) string {
193192
// formatSize converts bytes to human-readable format matching Docker's style
194193
// Returns format like "256MB" (decimal units, no space, matching `docker images`)
195194
func formatSize(bytes int64) string {
196-
formatted := units.HumanSize(float64(bytes))
197-
// Remove space between number and unit to match Docker format (e.g., "256 MB" -> "256MB")
198-
return strings.ReplaceAll(formatted, " ", "")
195+
return units.CustomSize("%.2f%s", float64(bytes), 1000.0, []string{"B", "kB", "MB", "GB", "TB", "PB", "EB"})
199196
}

0 commit comments

Comments
 (0)