1 | ;
|
2 |
|
3 | const sprintf = require('./format');
|
4 |
|
5 | module.exports = function (bytes) {
|
6 | var size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
7 | var factor = Math.floor((bytes.toString().length - 1) / 3);
|
8 | return sprintf("%s%s", Math.floor(100 * bytes / Math.pow(1024, factor)) / 100, size[factor]);
|
9 | };
|