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

Introduce method for formatting file size #29

Closed
abjerner opened this issue Jun 9, 2022 · 0 comments
Closed

Introduce method for formatting file size #29

abjerner opened this issue Jun 9, 2022 · 0 comments

Comments

@abjerner
Copy link
Member

abjerner commented Jun 9, 2022

Since formatting a file size (byte count) is something we do over and over again, it's a good candiate for adding to Skybrud.Essentials.

It's worth noticing that there are both a decimal format (1000 bytes is 1 KB), and a binary format (1024 bytes is 1 KiB), but also that KB is commonly used instead of KiB to refer to 1024 bytes.

Usage could be something like:

Implicit (binary, but with decimal units - technically incorrect, but commonly used)

// Returns "1 KB"
string formatted = StringUtils.FormatFileSize(1024);

Default (binary, but with decimal units - technically incorrect, but commonly used)

// Returns "1 KB"
string formatted = StringUtils.FormatFileSize(1024, FileSizeFormat.Default);

Binary

// Returns "1 KiB"
string formatted = StringUtils.FormatFileSize(1024, FileSizeFormat.Binary);

or:

// Returns "1 KiB"
string formatted = StringUtils.FormatFileSize(1024, FileSizeFormat.Kibi);

Decimal

// Returns "1 KB"
string formatted = StringUtils.FormatFileSize(1000, FileSizeFormat.Decimal);

or:

// Returns "1 KB"
string formatted = StringUtils.FormatFileSize(1000, FileSizeFormat.Kilo);
@abjerner abjerner self-assigned this Jun 9, 2022
abjerner added a commit that referenced this issue Jul 4, 2022
This adds a way to format a given file size in to either kilobytes, kibibytes or a mix of the to.

Implements #29
@abjerner abjerner closed this as completed Jul 4, 2022
abjerner added a commit that referenced this issue Jul 4, 2022
Failed saving the file, so here's an extra commit ¯\_(ツ)_/¯

See #29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant