From 42c3c02f9564450ea83f917c1274f0da24ddcfdd Mon Sep 17 00:00:00 2001 From: Celina Kilcrease Date: Tue, 17 Apr 2018 11:37:56 -0400 Subject: [PATCH] converting filesize to readable format --- notebook/static/base/js/utils.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/notebook/static/base/js/utils.js b/notebook/static/base/js/utils.js index c7f51ecef..a1074e6b4 100644 --- a/notebook/static/base/js/utils.js +++ b/notebook/static/base/js/utils.js @@ -1041,9 +1041,25 @@ define([ var format_filesize = function(filesize) { if (filesize) { - return filesize + " bytes"; + return (convertFileSize(filesize)); } } + + var convertFileSize = function(filesize){ + var units = ['B', 'kB', 'MB', 'GB', 'TB']; + var base = 1000; + if (Math.abs(filesize) < base){ + return filesize + " B"; + } + var u = -1; + do{ + filesize /= base; + u++; + } while(Math.abs(filesize) >= base && u < units.length - 1); + return filesize.toFixed(1) + " " + units[u]; + + } + // javascript stores text as utf16 and string indices use "code units", // which stores high-codepoint characters as "surrogate pairs",