Skip to content
Snippets Groups Projects
Commit 945e55f8 authored by Alexander Rose's avatar Alexander Rose
Browse files

add formated file size

parent 866a30ab
No related branches found
No related tags found
No related merge requests found
......@@ -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]);
}
}
......
......@@ -203,3 +203,9 @@ export function formatProgress(p: Progress) {
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment