{"id":28395064,"url":"https://github.com/usercode/dataunits","last_synced_at":"2026-02-23T23:34:52.200Z","repository":{"id":290161190,"uuid":"973559645","full_name":"usercode/DataUnits","owner":"usercode","description":"DataUnits allows easier handling of byte size representation. (Bytes, KB, MB, GB, TB)","archived":false,"fork":false,"pushed_at":"2025-05-04T09:47:36.000Z","size":71,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-23T08:53:12.958Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/usercode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-27T08:50:33.000Z","updated_at":"2025-05-04T09:47:39.000Z","dependencies_parsed_at":"2025-06-27T01:31:58.364Z","dependency_job_id":"483d704b-c72d-4f4c-a22a-1e9903761b81","html_url":"https://github.com/usercode/DataUnits","commit_stats":null,"previous_names":["usercode/dataunits"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/usercode/DataUnits","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercode%2FDataUnits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercode%2FDataUnits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercode%2FDataUnits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercode%2FDataUnits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usercode","download_url":"https://codeload.github.com/usercode/DataUnits/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercode%2FDataUnits/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29760700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T21:02:23.375Z","status":"ssl_error","status_checked_at":"2026-02-23T20:58:31.539Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-31T19:30:21.372Z","updated_at":"2026-02-23T23:34:52.172Z","avatar_url":"https://github.com/usercode.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DataUnits\nDataUnits allows easier handling of byte size representation. (Bytes, KB, MB, GB, TB)\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)\n[![NuGet](https://img.shields.io/nuget/v/DataUnits.svg?style=flat-square)](https://www.nuget.org/packages/DataUnits/)\n\n## How to use it\n\nYou can create a `ByteSize` object from bits, bytes, kilobytes, megabytes, gigabytes and terabytes.\n\n- JsonConverter and TypeConverter are already available.\n\n```c#\nByteSize bytes = ByteSize.FromBytes(10);\nByteSize kilobytes = ByteSize.FromKilobytes(10);\nByteSize megabytes = ByteSize.FromMegabytes(10);\nByteSize gigabytes = ByteSize.FromGigabytes(10);\nByteSize terabytes = ByteSize.FromTerabytes(10);\n```\n\n### Calculate bit rate\n```c#\nBitRate bitRate = ByteSize.FromBytes(1) / TimeSpan.FromSeconds(2); //4\nTimeSpan time = ByteSize.FromBytes(1) / BitRate.FromBits(4); //2\nByteSize byteSize = BitRate.FromBits(8) * TimeSpan.FromSeconds(2); //2\n```\n\n### Parsable \n```c#\nByteSize bytes = ByteSize.Parse(\"1\"); //if no size is specified, byte is used\nByteSize bytes = ByteSize.Parse(\"1 B\");\nByteSize bytes = ByteSize.Parse(\"1 b\"); //ignores case\nByteSize kilobytes = ByteSize.Parse(\"1 KB\");\nByteSize gigabytes = ByteSize.Parse(\" 1GB \"); //ignores whitespaces\nByteSize gigabytes = ByteSize.Parse(\"1.1 GB\", CultureInfo.Invariant);\n```\n\n### Formattable\n```c#\nByteSize.FromBytes(1024).ToString(CultureInfo.InvariantCulture); // \"1 KB\"\nByteSize.FromKilobytes(1.5).ToString(CultureInfo.InvariantCulture); // \"1.5 KB\"\n\n//use explicit unit\nByteSize.FromMegabytes(1).ToString(ByteUnit.Kilobyte, null, CultureInfo.InvariantCulture); //\"1,024 KB\"\n```\n\n### Comparable\n```c#\nbool result = ByteSize.FromBytes(1024) == ByteSize.FromKilobytes(1);\nbool result = ByteSize.FromBytes(100) \u003e ByteSize.FromKilobytes(1);\n```\n\n### Implicit operators\n```c#\nlong value = ByteSize.FromBytes(1024); //returns byte value\n\nByteSize size = 1024; //use byte unit\n```\n\n### Arithmetic operations\n\n```c#\nByteSize a = ByteSize.FromBytes(10) + ByteSize.FromMegabytes(5);\nByteSize b = ByteSize.FromMegabytes(100) - ByteSize.FromMegabytes(5);\n\na = a.AddTerabytes(10);\n```\n\n### JSON\n```c#\nJsonSerializer.Serialize(ByteSize.FromKilobytes(1)); //returns byte value as number\n```\n\n### TypeConverter\n\nIn your appsettings.json you can specify the byte size in different types:\n\n```json\n{\n  \"MaxContentLength\": 1024\n}\n```\n\n```json\n{\n  \"MaxContentLength\": \"1024\"\n}\n```\n\n```json\n{\n  \"MaxContentLength\": \"1 KB\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusercode%2Fdataunits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusercode%2Fdataunits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusercode%2Fdataunits/lists"}