Add progress to packet loading (and download links)

This commit is contained in:
Ross
2020-04-29 18:16:29 +01:00
parent f6610cc5e9
commit 5c2e1a0f3d
5 changed files with 94 additions and 23 deletions
+15 -1
View File
@@ -3,7 +3,9 @@
* @param {array} array
*/
export function shuffleArray(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
var currentIndex = array.length,
temporaryValue,
randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
@@ -26,3 +28,15 @@ export function urltoFile(url, filename, mimeType) {
return new File([buf], filename, { type: mimeType });
});
}
export function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return "0 Bytes";
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
}