Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
FormData
/
js
:
SizeStructure.js
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
var SizeStructure = function() { this.SizeRange = ["Bits", "KB", "MB", "GB", "TB"]; this.SpeedRange = ["Bit/s", "KB/s", "MB/s", "GB/s", "TB/s"]; //Returns number of bytes as structure string E.g. 1076 as input returns 1.05KB this.BytesToStructuredString = function(bytes) { if(bytes < 1) return "0 Bit"; var i = Math.floor(Math.log(bytes) / Math.log(1024)); return (bytes / Math.pow(1024, i)).toFixed(2) + this.SizeRange[i]; }; //Returns number of bytes/sec as structure string E.g. 1076 as input returns 1.05KB/s this.SpeedToStructuredString = function(speed) { if(speed < 1) return "0 Bit/s"; var i = Math.floor(Math.log(speed) / Math.log(1024)); return (speed / Math.pow(1024, i)).toFixed(2) + this.SpeedRange[i]; }; }