Introduction

edit

Meziantou.Framework.ByteSize provides ByteSize, a struct that holds a number of bytes, such as the size of a file, a download or a memory limit. It turns 1536000 into 1.54MB or 1.46MiB for display, reads 10MB from a configuration file, and compares and adds sizes.

Decimal and binary units

ByteSize supports two families of units:

Decimal unitsValueBinary unitsValue
kB (kilobyte)1,000 byteskiB (kibibyte)1,024 bytes
MB (megabyte)1,000² bytesMiB (mebibyte)1,024² bytes
GB (gigabyte)1,000³ bytesGiB (gibibyte)1,024³ bytes
TB (terabyte)1,000⁴ bytesTiB (tebibyte)1,024⁴ bytes
PB (petabyte)1,000⁵ bytesPiB (pebibyte)1,024⁵ bytes
EB (exabyte)1,000⁶ bytesEiB (exbibyte)1,024⁶ bytes

B is a byte. The ByteSizeUnit enum has one member per unit, from Byte to ExbiByte, and its value is the number of bytes of the unit.

What you can do with it

Namespaces

ByteSize and ByteSizeUnit are in the Meziantou.Framework namespace.