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

Incorrect filesize(1024) == '1.02 KiB' #150

Closed afanasy closed 2 years ago

afanasy commented 2 years ago
filesize(1024) == '1.02 KiB'

on version 9.0.1 (should be 1 KiB). Thanks for the great lib!

avoidwork commented 2 years ago

You've missed the change to base 10 by default.

avoidwork commented 2 years ago
Screenshot 2022-06-11 081543 Screenshot 2022-06-11 081604

i know opening issues is easy, but maybe ... read the readme.md first, or try it?

afanasy commented 2 years ago

@avoidwork Thank you for taking time to provide the screenshots! I've been using the lib for years, and run into the problem while upgrading from 6.x to the latest 9.x version last week, and even reading the readme.md multiple times couldn't help to make sense of the new base 2/10/iec/jedec defaults. The point is filesize(1024) == '1.02 KiB' is incorrect, meaning the defaults are wrong (I believe), because by any standard 1024 bytes are not 1.02 KiB but 1 KiB. Now I can't just bump the version to the latest (9.x), because it shows the wrong values (and I'm ok if it would show correct KiB values, instead of previous KB values, but it doesn't), so I ended up using 8.x.

avoidwork commented 2 years ago

@afanasy i think i understand your concern, however base10 vs base2 is not something i'm going to argue; it's also not a bug.

there's 3 groups for this "problem", the people that think it's always only base2, the ones that deal with advertising which is base10, and then the users. the first group is stuck in the past.

avoidwork commented 2 years ago

@afanasy you might benefit from using the partial application to keep your code on point. you could also open a PR to put it back to base2. i do not have a strong opinion, as imo affordance is more important than a single use case being "correct".