{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/14234","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/14234/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/14234/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/14234/events","html_url":"https://github.com/dotnet/corefx/issues/14234","id":193779675,"number":14234,"title":"API Proposal: ByteSize Struct","user":{"login":"benaadams","id":1142958,"avatar_url":"https://avatars.githubusercontent.com/u/1142958?v=3","gravatar_id":"","url":"https://api.github.com/users/benaadams","html_url":"https://github.com/benaadams","followers_url":"https://api.github.com/users/benaadams/followers","following_url":"https://api.github.com/users/benaadams/following{/other_user}","gists_url":"https://api.github.com/users/benaadams/gists{/gist_id}","starred_url":"https://api.github.com/users/benaadams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benaadams/subscriptions","organizations_url":"https://api.github.com/users/benaadams/orgs","repos_url":"https://api.github.com/users/benaadams/repos","events_url":"https://api.github.com/users/benaadams/events{/privacy}","received_events_url":"https://api.github.com/users/benaadams/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-12-06T14:02:00Z","updated_at":"2016-12-06T14:15:04Z","closed_at":null,"body":"Like TimeSpan to remove ambiguity in sizes e.g. https://github.com/aspnet/KestrelHttpServer/issues/1247\r\n\r\n## Suggested API\r\n\r\n```csharp\r\npublic struct ByteSize\r\n{\r\n    public ulong TotalBytes { get; }\r\n\r\n    public ByteSize(ulong sizeInBytes)\r\n    {\r\n        TotalBytes = sizeInBytes;\r\n    }\r\n\r\n    public static implicit operator ulong(ByteSize size)\r\n    {\r\n        return size.TotalBytes;\r\n    }\r\n\r\n    public static implicit operator ByteSize(ulong sizeInBytes)\r\n    {\r\n        return new ByteSize(sizeInBytes);\r\n    }\r\n\r\n    public static readonly ByteSize Zero = new ByteSize(0UL);\r\n    public static readonly ByteSize MinValue = new ByteSize(ulong.MinValue);\r\n    public static readonly ByteSize MaxValue = new ByteSize(ulong.MaxValue);\r\n\r\n    public ushort Bytes => (ushort)(TotalBytes % 1024ul);\r\n    public ushort Kilobytes => (ushort)(TotalBytes % (1024ul * 1024ul));\r\n    public ushort Megabytes => (ushort)(TotalBytes % (1024ul * 1024ul * 1024ul));\r\n    public ushort Gigabytes => (ushort)(TotalBytes % (1024ul * 1024ul * 1024ul * 1024ul));\r\n    public ushort Terabytes => (ushort)(TotalBytes % (1024ul * 1024ul * 1024ul * 1024ul * 1024ul));\r\n    public ushort Exabytes => (ushort)(TotalBytes % (1024ul * 1024ul * 1024ul * 1024ul * 1024ul * 1024ul));\r\n    public ushort Zettabytes => (ushort)(TotalBytes % (1024ul * 1024ul * 1024ul * 1024ul * 1024ul * 1024ul));\r\n    public ulong Yottabytes => TotalBytes % (1024ul * 1024ul * 1024ul * 1024ul * 1024ul * 1024ul);\r\n\r\n    public double TotalKilobytes => TotalBytes / (double)1024ul;\r\n    public double TotalMegabytes => TotalBytes / (double)(1024ul * 1024ul);\r\n    public double TotalGigabytes => TotalBytes / (double)(1024ul * 1024ul * 1024ul);\r\n    public double TotalTerabytes => TotalBytes / (double)(1024ul * 1024ul * 1024ul * 1024ul);\r\n    public double TotalExabytes => TotalBytes / (double)(1024ul * 1024ul * 1024ul * 1024ul);\r\n    public double TotalZettabytes => TotalBytes / (double)(1024ul * 1024ul * 1024ul * 1024ul * 1024ul);\r\n    public double TotalYottabytes => TotalBytes / (double)(1024ul * 1024ul * 1024ul * 1024ul * 1024ul * 1024ul);\r\n\r\n    public override string ToString();\r\n    public string ToString(Format standard);\r\n\r\n    public static ByteSize Parse(string value);\r\n    public static bool TryParse(string value, out ByteSize size);\r\n    public static bool TryParseExact(string value, Format standard, out ByteSize size);\r\n    public static ByteSize FromKilobytes(double value);\r\n    public static ByteSize FromMegabytes(double value);\r\n    public static ByteSize FromGigabytes(double value);\r\n    public static ByteSize FromTerabytes(double value);\r\n    public static ByteSize FromPetabytes(double value);\r\n    public static ByteSize FromExabytes(double value);\r\n    public static ByteSize FromZettabytes(double value);\r\n    public static ByteSize FromYottabytes(double value);\r\n\r\n    public enum Format\r\n    {\r\n        Memory = 0,\r\n        JEDEC = Memory,\r\n        Decimal = 1,\r\n        IEC = Decimal\r\n    }\r\n}\r\n```\r\n\r\n## Open Questions\r\n\r\nFormat for kilobyte vs kibibyte and decimal vs binary sizes"},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/265159576","html_url":"https://github.com/dotnet/corefx/issues/14234#issuecomment-265159576","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/14234","id":265159576,"user":{"login":"NickCraver","id":454813,"avatar_url":"https://avatars.githubusercontent.com/u/454813?v=3","gravatar_id":"","url":"https://api.github.com/users/NickCraver","html_url":"https://github.com/NickCraver","followers_url":"https://api.github.com/users/NickCraver/followers","following_url":"https://api.github.com/users/NickCraver/following{/other_user}","gists_url":"https://api.github.com/users/NickCraver/gists{/gist_id}","starred_url":"https://api.github.com/users/NickCraver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NickCraver/subscriptions","organizations_url":"https://api.github.com/users/NickCraver/orgs","repos_url":"https://api.github.com/users/NickCraver/repos","events_url":"https://api.github.com/users/NickCraver/events{/privacy}","received_events_url":"https://api.github.com/users/NickCraver/received_events","type":"User","site_admin":false},"created_at":"2016-12-06T14:15:04Z","updated_at":"2016-12-06T14:15:04Z","body":"If we did the proposal, it should include also the kibibyte, mebi, gibibyte, etc. series. These are very commonly needed in networking, SSD/HDD storage, and other bits.\r\n\r\nBonus: *which* is used varies on storage by platform (e.g. macOS uses gigibyte, Windows uses gigabyte)."}}
{"actor":{"display_login":"NickCraver"}}