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

feat(parseFileSize): Added parseFileSize function to parse a human readable file size to number of bytes #769

Merged
merged 1 commit into from
Sep 22, 2023

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Sep 21, 2023

The function is migrated from Nextcloud core. It will parse a human readable file size, like 2 KiB or 2 KB to machine usable number of bytes. e.g. 2 KiB => 2048 bytes, 2 KB => 2000 bytes.

It also allows to force reading the number as binary prefix, meaning 2 KB will be interpreted as 2048 bytes like on some systems were the incorrect unit is used.

…readable file size to number of bytes

The function is migrated from Nextcloud core. It will parse a human readable file size,
like `2 KiB` or `2 KB` to machine usable number of bytes.
e.g. `2 KiB` => 2048 bytes, `2 KB` => 2000 bytes.
It also allows to force reading the number as binary prefix,
meaning `2 KB` will be interpreted as 2048 bytes like on some systems were the incorrect unit is used.

Signed-off-by: Ferdinand Thiessen <[email protected]>
@susnux susnux added the enhancement New feature or request label Sep 21, 2023
@susnux susnux requested review from skjnldsv and szaimen September 21, 2023 23:31
@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

Merging #769 (e41200b) into master (51544f4) will increase coverage by 0.35%.
Report is 3 commits behind head on master.
The diff coverage is 90.90%.

@@            Coverage Diff             @@
##           master     #769      +/-   ##
==========================================
+ Coverage   77.33%   77.69%   +0.35%     
==========================================
  Files          17       17              
  Lines         406      417      +11     
  Branches      109      111       +2     
==========================================
+ Hits          314      324      +10     
- Misses         91       92       +1     
  Partials        1        1              
Files Changed Coverage Δ
lib/humanfilesize.ts 96.15% <90.90%> (-3.85%) ⬇️

@susnux
Copy link
Contributor Author

susnux commented Sep 22, 2023

Move to this library to deprecate OC.Util.computerFileSize

@susnux susnux merged commit 02439e9 into master Sep 22, 2023
10 checks passed
@susnux susnux deleted the feat/parseFileSize branch September 22, 2023 09:19
@skjnldsv skjnldsv mentioned this pull request Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants