number_to_human_size helper to “format bytes into a more understandable representation” (used e.g. to display the size of ActionText embeds) displays 1024 bytes as 1 KB. However the IEC/ISO standards nowadays seem to reserve the K, M, G, etc prefixes for powers of 1000 (in line with the metric system), and instead denotes multiples of 1024 bytes with the prefixes Ki, Mi, Gi, etc. This is apparently what e.g. Ubuntu or macOS have been doing for a while.
Shouldn’t ActionView’s helper follow these standards, i.e. either report 1024 bytes as 1.024 KB or 1 KiB, and not 1 KB, to avoid confusion?
I initially became confused when realizing a file displayed as 856 KB in macOS (= 855.538 bytes) shows up as 835.49 KB when embedded in ActionText.
I guess this could be resolved as follows:
- Use the prefixes Ki/Mi/Gi for multiples of 1024 instead of the current K/M/G
- By default, let the method continue to use multiples of 1024, but add an option to get multiples of 1000 instead
- Optionally and separately, in a future version of rails change the default to multiples of 1000
Understood. What is the best way to ensure ActionText’s embed captions match the standards and e.g macOS/Ubuntu show?
a file displayed as 856 KB in macOS (= 855.538 bytes) shows up as 835.49 KB when embedded in ActionText
@sdubois, if you’re referring to the Trix editor’s rendering of the file size, I think you might want to check out the Trix repository. After a little digging around, I found what appears to be a configurable filesize formatter. Someone at Basecamp seems to have already anticipated the IEC / SI conflict — it might be as straightforward as changing
Trix.config.fileSize.prefix. But I already digress, I don’t think this is a discussion for the RoR core forum.
Thank you @jas14, nice find! This works to have base 1000 with KB/MB units:
Trix.config.fileSize.prefix = "SI"
NB: For those who want KiB/MiB etc, this doesn’t seem to work, it still displays “KB”:
Trix.config.fileSize.prefix = "IEC"
Trix.config.lang.KB = "KiB" // and same for MiB, etc