avoidwork / filesize.js

JavaScript library to generate a human readable String describing the file size
https://filesizejs.com
BSD 3-Clause "New" or "Revised" License
1.61k stars 97 forks source link

Use correct units for base 2 #80

Closed ryank109 closed 8 years ago

ryank109 commented 8 years ago

For formatting the data size with base 2, the units need to be kiB, MiB, GiB instead of kB, MB, GB according to IEC standards.

avoidwork commented 8 years ago

Hi,

Should the standard be a parameter? SI and JEDEC are currently supported, to do a third I feel that we need to specify which base 2 standard you expect for output.

avoidwork commented 8 years ago

https://en.wikipedia.org/wiki/Binary_prefix https://en.wikipedia.org/wiki/IEC_80000-13

ryank109 commented 8 years ago

Not sure if you need a parameter for this, since SI = base10, (Ki, Mi, Gi) = base2? I was just noticing that the symbols were wrong for the formatted outputs.

There might be also concerns for changing this that might affect the current usage of the library. So, if I may suggest, have the default be base 10 instead of base 2? That way, people do not get any sudden changes in their application and have correct number and units. :)

avoidwork commented 8 years ago

Oh boy, people wouldn't be happy! 2.0.x was base 10, and there's bugs about how "your math is wrong" or something silly.

JEDEC (base 2) is the standard for memory, and is what most software & people expect to read. IEC is a newer representation, and I think it makes sense as a feature, but I guarantee you it should be an option and not a default. The majority of the existing user base is expecting JEDEC by default; it's a pretty big user base stats.

ryank109 commented 8 years ago

You are definitely right about how it's being used. It seems the standard does note that it is misusing the units to avoid confusion, but also mentions that it is deprecated as well. https://en.wikipedia.org/wiki/JEDEC_memory_standards#cite_note-4 -- pardon my reference to the wiki page.. :)

I guess I can always pass in base 10 option for format, so not necessary to add anything. If you feel there should be more discussion around this, feel free to keep the issue open, otherwise, you can close it. Thanks.

avoidwork commented 8 years ago

ok :+1: