diff options
Diffstat (limited to 'Master/texmf-dist/source/support/tlcockpit/src/main/scala/TLCockpit/Utils.scala')
-rw-r--r-- | Master/texmf-dist/source/support/tlcockpit/src/main/scala/TLCockpit/Utils.scala | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Master/texmf-dist/source/support/tlcockpit/src/main/scala/TLCockpit/Utils.scala b/Master/texmf-dist/source/support/tlcockpit/src/main/scala/TLCockpit/Utils.scala new file mode 100644 index 00000000000..fb364f12f80 --- /dev/null +++ b/Master/texmf-dist/source/support/tlcockpit/src/main/scala/TLCockpit/Utils.scala @@ -0,0 +1,18 @@ +package TLCockpit + +object Utils { + /** + * @see https://stackoverflow.com/questions/3263892/format-file-size-as-mb-gb-etc + * @see https://en.wikipedia.org/wiki/Zettabyte + * @param fileSize Up to Exabytes + * @return + */ + def humanReadableByteSize(fileSize: Long): String = { + if(fileSize <= 0) return "0 B" + // kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta + val units: Array[String] = Array("B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") + val digitGroup: Int = (Math.log10(fileSize)/Math.log10(1024)).toInt + f"${fileSize/Math.pow(1024, digitGroup)}%3.1f ${units(digitGroup)}" + } + +} |