|
4 | 4 |
|
5 | 5 | # ByteFlow.Net |
6 | 6 |
|
7 | | -[](https://github.com/AndrewClements84/ByteFlow.Net/actions) |
8 | | -[](https://codecov.io/gh/AndrewClements84/ByteFlow.Net) |
9 | | -[](https://www.nuget.org/packages/ByteFlow.Net) |
10 | | -[](https://www.nuget.org/packages/ByteFlow.Net) |
11 | | -[](LICENSE.txt) |
| 7 | +[](https://github.com/AndrewClements84/ByteFlow.Net/actions) |
| 8 | +[](https://codecov.io/gh/AndrewClements84/ByteFlow.Net) |
| 9 | +[](https://www.nuget.org/packages/ByteFlow.Net) |
| 10 | +[](https://www.nuget.org/packages/ByteFlow.Net) |
| 11 | +[](LICENSE.txt) |
12 | 12 |  |
13 | 13 |
|
14 | | -A lightweight .NET library for converting bytes into **human-readable |
15 | | -formats** (KB, MB, GB, etc.) and back again. |
| 14 | +ByteFlow.Net — Convert bytes ⇄ human-readable formats with SI, IEC, culture-aware, and customizable units. Zero dependencies. |
16 | 15 |
|
17 | 16 | --- |
18 | 17 |
|
19 | 18 | ## ✨ Features |
20 | 19 |
|
21 | | -- Convert bytes into human-readable strings (`1234567 → "1.18 MB"`). |
22 | | -- Parse strings back into bytes (`"2.5 GB" → 2684354560`). |
23 | | -- Safe parsing with `TryParseHumanBytes`. |
24 | | -- Zero dependencies, just clean C#. |
25 | | -- Works on .NET Framework (4.6.1+) and all modern .NET versions (Core, |
26 | | - 5/6/7/8). |
| 20 | +- Convert raw byte counts into human-readable strings (e.g. `1234567 → "1.23 MB"`) |
| 21 | +- Parse human-readable strings back into bytes (`"2.5 GB" → 2684354560`) |
| 22 | +- Safe parsing via `TryParseHumanBytes` (no exception) |
| 23 | +- Support for both **IEC (KiB, MiB, GiB)** and **SI (KB, MB, GB)** unit standards |
| 24 | +- Culture-aware parsing/formatting (e.g. `"1,5 MB"` for cultures with comma decimal separators) |
| 25 | +- Customizable suffix sets (allow defining your own unit names/factors) |
| 26 | +- Alignment/padding helpers for nicely formatted output in tables or logs |
| 27 | +- Fully tested with **100% code coverage** |
| 28 | +- Zero external dependencies — pure C# |
27 | 29 |
|
28 | 30 | --- |
29 | 31 |
|
30 | 32 | ## 📦 Installation |
31 | 33 |
|
32 | | -Install from [NuGet](https://www.nuget.org/packages/ByteFlow.Net): |
| 34 | +Install via NuGet: |
33 | 35 |
|
34 | | -``` sh |
| 36 | +```bash |
35 | 37 | dotnet add package ByteFlow.Net |
36 | 38 | ``` |
37 | 39 |
|
38 | 40 | --- |
39 | 41 |
|
40 | 42 | ## 🚀 Usage |
41 | 43 |
|
42 | | -``` csharp |
43 | | -using ByteFlowNet; |
| 44 | +```csharp |
| 45 | +using ByteFlow; |
44 | 46 |
|
45 | | -// Convert bytes to human-readable string |
| 47 | +// Basic conversion |
46 | 48 | long size = 1234567; |
47 | | -Console.WriteLine(size.ToHumanBytes()); // "1.18 MB" |
48 | | -Console.WriteLine(size.ToHumanBytes(3)); // "1.177 MB" |
| 49 | +Console.WriteLine(size.ToHumanBytes()); // e.g. "1.18 MB" (default settings) |
| 50 | +Console.WriteLine(size.ToHumanBytes(3)); // more decimals |
49 | 51 |
|
50 | | -// Parse string back into bytes |
51 | | -long bytes = "2.5 GB".ToBytes(); // 2684354560 |
| 52 | +// Parsing string to bytes |
| 53 | +long bytes = "2.5 GB".ToBytes(); // default parsing (SI/IEC based on default) |
52 | 54 | Console.WriteLine(bytes); |
53 | 55 |
|
54 | 56 | // Safe parsing |
55 | 57 | if ("10 MB".TryParseHumanBytes(out var val)) |
56 | 58 | { |
57 | | - Console.WriteLine(val); // 10485760 |
| 59 | + Console.WriteLine(val); // prints bytes if successful |
58 | 60 | } |
| 61 | + |
| 62 | +// Using IEC explicitly |
| 63 | +Console.WriteLine(1536L.ToHumanBytes(2, UnitStandard.IEC)); // "1.50 KiB" |
| 64 | +long val2 = "1.50 KiB".ToBytes(UnitStandard.IEC); |
| 65 | + |
| 66 | +// Culture-aware parsing/formatting |
| 67 | +var de = new System.Globalization.CultureInfo("de-DE"); |
| 68 | +Console.WriteLine((1500L).ToHumanBytes(2, UnitStandard.SI, de)); // "1,50 KB" |
| 69 | +long val3 = "1,50 KB".ToBytes(UnitStandard.SI, de); |
| 70 | + |
| 71 | +// Custom suffix sets |
| 72 | +var custom = new[] { ("X", 1d), ("KX", 1000d), ("MX", 1000000d) }; |
| 73 | +string customStr = 5000L.ToHumanBytes(2, UnitStandard.SI, null, custom); // "5.00 KX" |
| 74 | +long customBytes = "5 KX".ToBytes(UnitStandard.SI, null, custom); |
59 | 75 | ``` |
60 | 76 |
|
61 | 77 | --- |
62 | 78 |
|
63 | | -## 🧪 Unit Tests |
64 | | - |
65 | | -Unit tests are included under the `tests/ByteFlowNet.Tests` project |
66 | | -using **xUnit**. |
| 79 | +## 🧪 Unit Tests & Code Coverage |
67 | 80 |
|
| 81 | +Unit tests are under `ByteFlow.Tests` (xUnit). |
68 | 82 | Run them with: |
69 | 83 |
|
70 | | -``` sh |
| 84 | +```bash |
71 | 85 | dotnet test |
72 | 86 | ``` |
73 | 87 |
|
74 | | ---- |
75 | | - |
76 | | -## 📊 Code Coverage |
77 | | - |
78 | | -Code coverage reports are automatically uploaded to |
79 | | -[Codecov](https://app.codecov.io/gh/AndrewClements84/ByteFlow.Net).\ |
80 | | -Current coverage: **100%** ✅ |
| 88 | +Coverage is tracked via Codecov — current coverage: **100%** ✅ |
81 | 89 |
|
82 | 90 | --- |
83 | 91 |
|
84 | | -## 🔮 Roadmap |
| 92 | +## 🧭 Alternatives / Comparisons |
85 | 93 |
|
86 | | -Planned features for upcoming releases: |
| 94 | +While there are other “bytes to human readable” .NET libraries out there, very few (if any) offer the combined feature set that **ByteFlow.Net** does: |
87 | 95 |
|
88 | | -- [ ] Support for both **IEC (binary: KiB, MiB)** and **SI (decimal: |
89 | | - KB, MB)** unit standards\ |
90 | | -- [ ] Culture-aware parsing (e.g., commas vs dots for decimals)\ |
91 | | -- [ ] Customizable suffix sets (allowing non-standard units)\ |
92 | | -- [ ] Performance benchmarking and optimizations for very large |
93 | | - inputs\ |
94 | | -- [ ] Additional helpers for formatting with alignment/padding |
| 96 | +- Support for both **IEC and SI** |
| 97 | +- Culture-aware parsing/formatting |
| 98 | +- Fully customizable suffix sets |
| 99 | +- Alignment/padding helpers |
| 100 | +- Zero dependencies |
| 101 | +- Complete test coverage |
| 102 | + |
| 103 | +So this library aims to be a robust one-stop solution for byte-size formatting. |
95 | 104 |
|
96 | 105 | --- |
97 | 106 |
|
98 | 107 | ## 🤝 Contributing |
99 | 108 |
|
100 | | -Contributions, issues, and feature requests are welcome!\ |
101 | | -Feel free to open a |
102 | | -[discussion](https://github.com/AndrewClements84/ByteFlow.Net/discussions) |
103 | | -or a [pull |
104 | | -request](https://github.com/AndrewClements84/ByteFlow.Net/pulls). |
| 109 | +Contributions, issues, and feature requests are always welcome! |
| 110 | +Feel free to open a [discussion](https://github.com/AndrewClements84/ByteFlow.Net/discussions) or a [pull request](https://github.com/AndrewClements84/ByteFlow.Net/pulls). |
105 | 111 |
|
106 | 112 | --- |
107 | 113 |
|
108 | 114 | ## ⭐ Support |
109 | 115 |
|
110 | | -If you find **ByteFlow.Net** useful, please consider giving it a star on |
111 | | -GitHub --- it helps others discover the project and shows your support. |
| 116 | +If you enjoy using **ByteFlow.Net**, a GitHub star helps more than you’d think — it boosts visibility and helps others find it. |
112 | 117 |
|
113 | 118 | --- |
114 | 119 |
|
115 | | - |
116 | 120 | ## 📄 License |
117 | 121 |
|
118 | | -This project is licensed under the MIT License – see the [LICENSE.txt](LICENSE.txt) file for details. |
| 122 | +Licensed under the MIT License — see [LICENSE.txt](LICENSE.txt) for details. |
0 commit comments