-
Notifications
You must be signed in to change notification settings - Fork 50
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
Support binary and decimal bytes (i.e. 1 kibi = 1024 b and 1 kb = 1000 b) #24
Merged
Merged
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
2449aa0
Migrate from project.json to .csproj
omar a31720c
Metric byte POC
omar 699457f
Add binary byte design doc
omar 16b3f5d
Create BinaryByteSize class
omar fc5ad2e
Add tests
omar a39c68a
Update design document
omar 78f9a92
Fix build
omar cc41b1e
Fix build
omar c131413
Remove net461 target framework
omar 9aa161f
Add DecimalByteSize
omar 6b778bc
Rename namespace to `ByteSize` and add tests
omar b0d990a
Revert min value, update release notes
omar db3cacc
Fix NuGet package properties
omar 669a456
Fix typo
omar 224e275
Combine Decimal and Binary ByteSize into a single struct
omar 0b520c3
Fix tests
omar 45bf4f9
Fix build
omar e025995
Merge commit 'd20566c66b1549abd478225553fb1ef0901b272d' into metric-byte
omar 223afd0
Prepare alpha2
omar ca4ef02
Update copyright dates
omar 6425b77
Fix #37 by avoiding division of a long/int64
omar 521a761
Change name of largest number properties
omar c475563
Update docs and make docker build rerunnable
omar 60a37b5
Update build and release notes
omar 4b0a046
Update release notes
omar fe8d560
Add ToBinaryString method
omar e52aa36
Update readme
omar 1721c66
Merge branch 'master' into metric-byte
omar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,4 @@ src/packages/** | |
*.ncrunch* | ||
*.ndproj | ||
*.nupkg | ||
**/project.lock.json | ||
src/ByteSize/pack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,6 @@ | ||
dist: trusty | ||
sudo: required | ||
|
||
env: | ||
global: | ||
- DOTNET_CLI_TELEMETRY_OPTOUT=1 | ||
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true | ||
|
||
before_install: | ||
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF | ||
- echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list | ||
- sudo apt-get update | ||
- sudo apt-get install mono-complete | ||
- sudo apt-get install referenceassemblies-pcl | ||
- mono --version | ||
- sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list' | ||
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893 | ||
- sudo apt-get update | ||
- sudo apt-get install dotnet-dev-1.0.0-preview2.1-003177 | ||
- export PATH=/usr/local/share/dotnet/:$PATH | ||
- dotnet --version | ||
|
||
language: csharp | ||
mono: none | ||
dotnet: 2.1.500 | ||
script: | ||
- make test | ||
|
||
- make test | ||
- make pack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
build: | ||
dotnet restore | ||
dotnet build src/ByteSizeLib | ||
dotnet build src | ||
|
||
test: | ||
dotnet restore | ||
dotnet build src/ByteSizeLib | ||
dotnet test src/ByteSizeLib.Tests | ||
dotnet test src/ByteSize.Tests | ||
|
||
package: | ||
dotnet restore | ||
dotnet pack src/ByteSizeLib -c Release -o pack | ||
pack: | ||
dotnet pack src/ByteSize -c Release -o pack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Binary Byte | ||
|
||
ByteSize started off with: | ||
|
||
- 1 kilobyte = 1024 bytes | ||
- 2 letter abbreviation (KB, GB etc.) | ||
|
||
See why [here](https://omar.io/2017/01/16/when-technically-right-is-wrong-kilobytes.html). | ||
|
||
Since then, there have been a few requests to support the [IEC binary prefix](https://en.wikipedia.org/wiki/Binary_prefix#kibi), | ||
see [issue#1](https://github.com/omar/ByteSize/issues/1) and [Humanizr/Humanizer/issues/592](https://github.com/Humanizr/Humanizer/issues/592). | ||
This document will include the rational for the design of implementing the IEC standard. | ||
|
||
## Research | ||
|
||
| Vendor | Abbreviation | Ratio | [IEC Standard] | Source | ||
| --- | --- | --- | --- | --- | ||
| ByteSize | KB, GB, etc. | 1 = 1024 | No | | ||
| GCP | KB, GB, etc. | 1 = 1024 | No | https://cloud.google.com/storage/pricing | ||
| AWS | KB, GB, etc. | 1 = 1024 | No | https://aws.amazon.com/ebs/features/ | ||
| AWS Glossary | KB, GB, etc. | 1 = 1000 | Yes | https://docs.aws.amazon.com/general/latest/gr/glos-chap.html | ||
| AWS Glossary | KiB, GiB, etc. | 1 = 1024 | Yes | https://docs.aws.amazon.com/general/latest/gr/glos-chap.html | ||
| Azure (RAM) | KiB, GiB, etc. | 1 = 1024 | Yes | https://azure.microsoft.com/en-gb/blog/largest-vm-in-the-cloud/ | ||
| Azure (Disk) | KB, GB, etc. | 1 = 1000 | Yes | https://azure.microsoft.com/en-gb/blog/largest-vm-in-the-cloud/ | ||
| Mac OS X Leopard + | KB, GB, etc. | 1 = 1000 | Yes | https://support.apple.com/en-us/HT201402 | ||
| iOS 11 + | KB, GB, etc. | 1 = 1000 | Yes | https://support.apple.com/en-us/HT201402 | ||
|
||
In summary, developers are _attempting_ to adhere to the IEC standard by either: | ||
|
||
- Changing the abbreviation and ratio to match the IEC binary standard, or; | ||
- Changing the ratio they've used in the past to match the decimal values | ||
|
||
[IEC Standard]: https://en.wikipedia.org/wiki/Binary_prefix#kibi | ||
|
||
## Implementation Considerations | ||
|
||
1. Two structs that represents the decimal (`DecimalByteSize`) and binary | ||
values (`BinaryByteSize`). | ||
- Pros | ||
- Clear separation of what's being represented by the object. | ||
- Solve the namespace collision that forced the `ByteSize` namespace. | ||
- Cons | ||
- Swapping between binary and decimal representation requires two | ||
objects. Maybe can provide a simple way to go from one to the other: | ||
`BinaryByteSize.FromDecimalByteSize` and | ||
`DecimalByteSize.FromBinaryByteSize`. No idea how valuable or needed | ||
this would be though. | ||
- Breaking change since `BinaryByteSize` has the same ratio as the | ||
original `ByteSize` class, but not the text representation. | ||
(See "Backwards Compatibility Note" below). | ||
- Backwards Compatibility Note | ||
- v1.x of ByteSize could ship with two additional structs | ||
`DecimalByteSize` and `BinaryByteSize` but keep `ByteSize` with it's | ||
current implementation. | ||
- v2.0 of ByteSize could break compatiblity and remove the `ByteSize` | ||
struct in favor of `DecimalByteSize` and `BinaryByteSize`. | ||
|
||
2. Single struct | ||
- Flat properties (e.g. `value.KiloByte` and `value.KibiByte`). | ||
- Pros | ||
- Single object that allows use of both standards. | ||
- Cons | ||
- Autocomplete lists will have twice as many methods and properties | ||
- Nested properties (e.g. `value.Decimal.KiloByte` and `value.Binary.KibiByte`). | ||
- Pros | ||
- Single object that allows use of both standards. | ||
- Cons | ||
- Autocomplete lists will have twice as many methods and properties |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've started to use your alpha-version and faced with problem with naming KB for Decimal. It seems that for Decimal it should be 'kB' instead of 'KB'.
https://en.wikipedia.org/wiki/Kilobyte
https://en.wikipedia.org/wiki/Mega-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be cool if you'll build version new alpha version before completing PR 😎