mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-18 11:55:46 +08:00
converting filesize to readable format
This commit is contained in:
parent
abe05dea42
commit
13933f396a
@ -1041,10 +1041,26 @@ 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",
|
||||
// which occupy two indices in the javascript string.
|
||||
|
Loading…
Reference in New Issue
Block a user