A .NET utility class for unambiguous byte size representation and conversion, adhering to IEC and NIST standards.
ByteSize is a .NET utility class that provides a structured, unambiguous way to represent and convert byte sizes in code. It solves the common confusion between decimal (KB, MB) and binary (KiB, MiB) units by adhering to IEC and NIST standards, ensuring consistent calculations across applications. The library offers a type-safe API for creating, manipulating, formatting, and parsing byte size values.
.NET developers who need to handle file sizes, memory allocations, network bandwidth, or any data quantities expressed in bytes, especially those requiring strict adherence to unit standards.
Developers choose ByteSize because it eliminates ambiguity in byte size calculations, provides a clean, intuitive API similar to System.TimeSpan, and ensures compliance with industry standards for unit representation, reducing bugs and improving code readability.
ByteSize is a utility class that makes byte size representation in code easier by removing ambiguity of the value being represented. ByteSize is to bytes what System.TimeSpan is to time.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Adheres strictly to IEC/NIST standards, clearly separating decimal (KB) and binary (KiB) units, as emphasized in the README's philosophy and usage sections to eliminate ambiguity.
Provides a single struct similar to System.TimeSpan, enabling intuitive creation and manipulation via methods like ByteSize.FromMegaBytes(1.5), with direct property access for all unit representations.
Supports parsing from varied string formats (e.g., '1.5 gib') and customizable ToString output with localization, leveraging culture-specific number separators as detailed in the String Representation section.
Allows addition, subtraction, multiplication, and division between ByteSize objects, making complex calculations straightforward, as demonstrated in the Usage examples with operators like + and -.
Version 2 introduced a significant breaking change by switching default ratios (1 KB = 1000 B), requiring code updates for existing v1 users, as warned in the README's 'HUGE BREAKING CHANGE' section.
v2 dropped support for all platforms except netstandard1.0 and net45, limiting compatibility with older .NET versions or environments outside these targets, which could hinder adoption in legacy systems.
Explicitly does not support the legacy ratio of 1 KB = 1024 B, forcing users to migrate to KiB for binary units, which might be inconvenient for teams tied to outdated conventions.