Skip to content

EN_Utils

Francisco M. E edited this page Jan 20, 2019 · 2 revisions

Utils

Magnitudes (enum)

  • BINARY: 0
  • DECIMAL: 1

Sample:

const Utils = require('fs-hard-drive').Utils;

console.log(Utils.Magnitudes.BINARY);
console.log(Utils.Magnitudes.DECIMAL);

prettySize (function)

Transform Bytes to human language, sample:

const Utils = require('fs-hard-drive').Utils;

console.log(Utils.prettySize(512)); // Print '512 Bytes'
console.log(Utils.prettySize(1024)); // Print '1KiB'
console.log(Utils.prettySize(1024, Utils.Magnitudes.BINARY)); // Print '1KiB'
console.log(Utils.prettySize(1000, Utils.Magnitudes.DECIMAL)); // Print '1kB'

Extra information

---------------------------------------------------
                decimal                 binary
---------------------------------------------------
kilobyte (kB) 	10^3 	kibibyte (KiB) 	2^10
megabyte (MB) 	10^6 	mebibyte (MiB) 	2^20
gigabyte (GB) 	10^9 	gibibyte (GiB) 	2^30
terabyte (TB) 	101^2 	tebibyte (TiB) 	2^40
petabyte (PB) 	101^5 	pebibyte (PiB) 	2^50
exabyte (EB) 	101^8 	exbibyte (EiB) 	2^60
zettabyte (ZB) 	102^1 	zebibyte (ZiB) 	2^70
yottabyte (YB) 	102^4 	yobibyte (YiB) 	2^80
---------------------------------------------------