Takes an integer (referring to number of bytes) and returns an optimally human-readable binary-prefixed byte size (KiB, MiB, GiB, TiB, PiB, EiB). The function is vectorised.

human_filesize(x)

Arguments

x

A positive integer, i.e. the number of bytes (B). Can be a vector of file sizes.

Value

A character vector.

Author

Floris Vanderhaeghe, floris.vanderhaeghe@inbo.be

Examples

human_filesize(7845691)
#> [1] "7.5 MiB"
v <- c(12345, 456987745621258)
human_filesize(v)
#> [1] "12.1 KiB"  "415.6 TiB"