Skip to content

Conversation

@updevru
Copy link

@updevru updevru commented Oct 29, 2025

Refactor: replace external size-formatting dependency with internal utilities.

  • Removed dependency on github.com/c2h5oh/datasize.
  • Added utilities in util/bytes.go:
    • String formatting of bytes using binary units with integer output: ByteToHumanReadable(uint64) → "KiB/MiB/GiB/TiB/PiB/EiB".
    • Conversions from bytes to binary units with fractional precision: ByteToKBytes/…/ByteToEBytes(int64) → float64.
  • Updated usages:
    • frac/common/info.go: sizes are printed via util.ByteToHumanReadable.
    • storeapi/docs_stream.go and util/log_helpers.go: sizes in logs via util.ByteToHumanReadable.
    • util/util.go: SizeToUnit now uses the new converters; removed SizeStr.
  • Added tests util/bytes_test.go covering:
    • Basic cases, thresholds, ±1 around thresholds.
    • Very large values (including MaxUint64) without overflows.
  • String output now explicitly uses binary units (KiB/MiB/…), removing ambiguity between binary thresholds and decimal suffixes.
  • Avoided uint64 → int64 casts in formatting to prevent overflows.

Motivation:

  • Reduce third-party dependencies.
  • Clear, consistent unit semantics (binary units and thresholds).
  • Controlled formatting for logs/strings and predictable conversions for metrics.

Affected areas:

  • Logging and string formatting of sizes.
  • Helper utilities for size conversions.
  • Unit tests for formatting.

Backwards compatibility:

  • Log string format changed: now using KiB/MiB/… suffixes with integer values (no fractional part). If fractional precision is needed in strings, this can be added later without breaking the current API.

Dependencies

  • Removed: github.com/c2h5oh/datasize
  • Used: github.com/alecthomas/units (directly in util/bytes.go)

Fixes #146


  • I have read and followed all requirements in CONTRIBUTING.md;
  • I used LLM/AI assistance to make this pull request;

@updevru updevru force-pushed the 146-unify-human-readable-format branch from 9fa58d9 to 2e19728 Compare October 30, 2025 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify package choice for human-readable formats

1 participant