Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Breaking: Differentiate between kilobyte/kibibyte and megabyte/mebibyte #9271

Closed
wants to merge 1 commit into from

Conversation

ThomasMeschke
Copy link
Contributor

Description
Noticed that the file size calculation mixes up the SI unit prefixes with the NIST/IEC unit prefixes, by taking "kb" and "mb" but calculating "kib" and "mib".
Fixed by providing both possibilities.

This therefore will break existing code!

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@ThomasMeschke ThomasMeschke changed the base branch from 4.6 to develop November 12, 2024 12:56
@ThomasMeschke ThomasMeschke changed the title [breaking] refactor: Differentiate between kilobyte/kibibyte and megabyte/mebibyte refactor: Breaking: Differentiate between kilobyte/kibibyte and megabyte/mebibyte Nov 12, 2024
@neznaika0
Copy link
Contributor

neznaika0 commented Nov 12, 2024

BC changes are directed to 4.6. The calculation method is made too simple. The designations must have an exact register:
b = bit
B = byte
k = kilo
K = kibi
https://physics.nist.gov/cuu/Units/binary.html
It is strange that such a thing is allowed. But for most 1 kb = 1 KB = 1024 byte

@ddevsr ddevsr added the wrong branch PRs sent to wrong branch label Nov 12, 2024
@michalsn
Copy link
Member

@ThomasMeschke While I agree with your arguments, I would like to hear from other maintainers about how we should handle this because we have a similar problem in the number_to_size helper, which makes calculations by using 1024 bytes but describes it with an SI multiplier (e.g. KB instead of KiB).

  1. We can either correct everything and distinguish properly IEC binary multiplier symbols and SI multiplier symbols
  2. Or add a note to the user guide to indicate that all calculations are made using the binary multiplier.

The first solution would introduce a BC break, but it would also straighten things out.

The second would tell developers how calculations work, but would still retain confusing symbols - at least for more technical folks... from an end-user perspective, I don't think they would care.

@michalsn michalsn added the breaking change Pull requests that may break existing functionalities label Nov 13, 2024
@ThomasMeschke
Copy link
Contributor Author

While I absolutely see the "no normal user would differentiate between kb and KB" argument, I would say most people using and integrating with CodeIgniter at least have a basic understanding of computer science and should (and most probably will) know the difference, which is why I think the "do it right instead of commenting to explain the wrong" way.

If we do however I would prefer the "KiB" way over the "KB" way to make it more clear, because upper and lower casing as the only difference would leave it more confusing in my opinion.
If "KB" yields another result than "kb" I would be more confused then when "KiB" and "kb" return different results, because you could then even strtolower the indicator and have "kib" and "KiB" being the same, as well as "kb" and "KB", but have a clear distinction between "kib" and "kb".

@samsonasik
Copy link
Member

I guess this mostly usage for academic purpose, and only for niche usage in real application.

It still a breaking change, and can't land to develop imo.

@ThomasMeschke
Copy link
Contributor Author

ThomasMeschke commented Nov 13, 2024

I made a new PR to the right branch:
#9277

This one can get closed.

@ThomasMeschke
Copy link
Contributor Author

I guess this mostly usage for academic purpose, and only for niche usage in real application.

It still a breaking change, and can't land to develop imo.

The way I noticed this is while implementing a file upload with a file size limitation, that did not match frontend to backend, because the frontend used 1000 (also in a wrong way, but that's a different story) and the CI-Backend used 1024.

Option would have been to copy the getSizeByUnit into my own Code, change the numbers to 1000 and call this instead, but this felt quite hacky. =D

@ddevsr
Copy link
Collaborator

ddevsr commented Nov 14, 2024

Closed, thanks!

@ddevsr ddevsr closed this Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Pull requests that may break existing functionalities wrong branch PRs sent to wrong branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants