For units of digital information, IEC (ISO/IEC 80000) values are used with SI prefixes (incompatible!)
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 6.1k
- Forks
- 2.2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
Description
I'm a "hunter" of the legacy SI suffixes (which are unfortunately used till this day for size of digital information). I've noticed that when pushing a Docker image to registry, "kB" and "MB" prefixes were used to indicate the size of layers that are being uploaded. Thankfully, kB is used instead of non-existing KB (some software does use KB), which means that all the units are SI units (i.e., "kilo-", "mega-" etc.).
I investigated the repo a bit, and although I didn't find a place/function where bytes are converted to human-readable units, I did find a few lines of code scattered across multiple files where conversion is made out of 1024 (things like 1024 * 1024). This means that the values that are being computed are multiples of 2 (or multiples of 2¹⁰). Such values are prefixed with binary prefixes that are also can be called IEC prefixes. See: https://en.wikipedia.org/wiki/Binary_prefix.
Basically, the values (numbers) are computed as a binary/IEC values (multiples of 2), but prefixes are printed/shown as a decimal/SI prefixes (multiples of 10). I think I made it clear that this is wrong, you can't mix them together.
Now, since 1024 is used (everywhere in this repo) for computing values, I think we can all agree that this is the right (and only) way to compute such values (I use 1024 too). When using SI units, the bytes must be divided by 1000, when using IEC units — by 1024. So, 1 kB (kilobyte) is 1000 B (bytes) and 1 KiB (kibibyte) is 1024 B (bytes). And here we are finally arriving to the main problem: kB are used instead of KiB, MB — instead of MiB and so on.
TL;DR is that units of size must be fixed/replaced by the correct IEC units. Not taking into consideration the fact that SI units should/must not be used at all regardless, the main issue is that SI units are confusing (and therefore are legacy units)! You can't tell if 1 MB is 1000² bytes or 1024² bytes, because a lot of people were taught that 1 kilobyte is 1024 bytes (majority most likely doesn't even know what kibibyte is!). IEC prefixes solve this confusion: if you see 1 MiB, you know for a fact that it is 1024² bytes.
The rules also state that values and unit must be separated by a (white)space, but in the Docker CLI no spaces are used.
There is a lot of software that uses IEC prefixes, I can share my list (of such software) that I recently started (which will be expanded over time). Each project completely follows the rules (space and correct IEC prefixes):
- git (rounds to 2 digits, with whitespace between value and unit)
- crates.io (rounds up to 2 digits, with whitespace between value and unit)
- nvim-tree.lua (rounds up to 2 digits, with whitespace between value and unit)
- syncthing.net (rounds up to 2 digits, with whitespace between value and unit)
- flathub.org (rounds up to 2 digits, with whitespace between value and unit)
In every project except git (I didn't even look into the source code, since there is no need) a single convert function is used to convert bytes to an appropriate unit. So the solution was simple in each and one of them. With Docker, it looks like much more work must be done to achieve the goal. Therefore, I can't provide any suggestions on how to go about solving the problem, but I can contribute. I guess we just have to find every place in the codebase where units are printed and fix them.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by searching the Docker CLI repository for uses of 1024 and code that formats byte counts, since the issue names no specific files or tests. Trace each displayed size and identify the relevant coverage before changing anything. Done means binary values consistently use IEC prefixes such as KiB and MiB, with the requested spacing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100