From 945e55f8a7027d06ae468b230de23bb00a1f4dcd Mon Sep 17 00:00:00 2001
From: Alexander Rose <alexander.rose@weirdbyte.de>
Date: Mon, 7 Mar 2022 22:05:33 -0800
Subject: [PATCH] add formated file size

---
 src/extensions/zenodo/ui.tsx | 14 ++++++++------
 src/mol-util/index.ts        |  6 ++++++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/extensions/zenodo/ui.tsx b/src/extensions/zenodo/ui.tsx
index 6745329ae..11954681d 100644
--- a/src/extensions/zenodo/ui.tsx
+++ b/src/extensions/zenodo/ui.tsx
@@ -14,6 +14,7 @@ import { Button } from '../../mol-plugin-ui/controls/common';
 import { OpenInBrowserSvg } from '../../mol-plugin-ui/controls/icons';
 import { ParameterControls } from '../../mol-plugin-ui/controls/parameters';
 import { PluginContext } from '../../mol-plugin/context';
+import { formatBytes } from '../../mol-util';
 import { ParamDefinition as PD } from '../../mol-util/param-definition';
 
 type ZenodoFile = {
@@ -75,19 +76,20 @@ function createImportParams(files: ZenodoFile[], plugin: PluginContext) {
     }
 
     for (const file of files) {
+        const label = `${file.key} (${formatBytes(file.size)})`;
         if (structureExts.has(file.type)) {
             const { format, isBinary } = structureExts.get(file.type)!;
-            modelOpts.push([`${file.links.self}|${format}|${isBinary}`, file.key]);
-            topologyOpts.push([`${file.links.self}|${format}|${isBinary}`, file.key]);
+            modelOpts.push([`${file.links.self}|${format}|${isBinary}`, label]);
+            topologyOpts.push([`${file.links.self}|${format}|${isBinary}`, label]);
         } else if (volumeExts.has(file.type)) {
             const { format, isBinary } = volumeExts.get(file.type)!;
-            volumeOpts.push([`${file.links.self}|${format}|${isBinary}`, file.key]);
+            volumeOpts.push([`${file.links.self}|${format}|${isBinary}`, label]);
         } else if (file.type === 'psf') {
-            topologyOpts.push([`${file.links.self}|${file.type}|false`, file.key]);
+            topologyOpts.push([`${file.links.self}|${file.type}|false`, label]);
         } else if (file.type === 'xtc' || file.type === 'dcd') {
-            coordinatesOpts.push([`${file.links.self}|${file.type}|true`, file.key]);
+            coordinatesOpts.push([`${file.links.self}|${file.type}|true`, label]);
         } else if (file.type === 'zip') {
-            compressedOpts.push([`${file.links.self}|${file.type}|true`, file.key]);
+            compressedOpts.push([`${file.links.self}|${file.type}|true`, label]);
         }
     }
 
diff --git a/src/mol-util/index.ts b/src/mol-util/index.ts
index 1cbd8ede5..4db05201c 100644
--- a/src/mol-util/index.ts
+++ b/src/mol-util/index.ts
@@ -202,4 +202,10 @@ export function formatProgress(p: Progress) {
     if (tp.isIndeterminate) return tp.message;
     const x = (100 * tp.current / tp.max).toFixed(2);
     return `${tp.message} ${x}%`;
+}
+
+export function formatBytes(count: number) {
+    const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
+    const i = Math.floor(Math.log(count) / Math.log(1024));
+    return `${(count / Math.pow(1024, i)).toFixed(2)} ${units[i]}`;
 }
\ No newline at end of file
-- 
GitLab