UNPKG

molstar

Version:

A comprehensive macromolecular library.

54 lines 2.07 kB
"use strict"; /** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getFileInfo = void 0; // TODO only support compressed files for which uncompression support is available??? // TODO store globally with decompression plugins? var compressedExtList = ['gz', 'zip']; // TODO store globally with parser plugins? var binaryExtList = ['bcif', 'ccp4', 'dcd']; function getFileInfo(file) { var path; var compressed; var protocol = ''; if (file instanceof File) { path = file.name; } else if (file instanceof Blob) { path = ''; } else { path = file; } var queryIndex = path.lastIndexOf('?'); var query = queryIndex !== -1 ? path.substring(queryIndex) : ''; path = path.substring(0, queryIndex === -1 ? path.length : queryIndex); var name = path.replace(/^.*[\\/]/, ''); var base = name.substring(0, name.lastIndexOf('.')); var nameSplit = name.split('.'); var ext = nameSplit.length > 1 ? (nameSplit.pop() || '').toLowerCase() : ''; var protocolMatch = path.match(/^(.+):\/\/(.+)$/); if (protocolMatch) { protocol = protocolMatch[1].toLowerCase(); path = protocolMatch[2] || ''; } var dir = path.substring(0, path.lastIndexOf('/') + 1); if (compressedExtList.includes(ext)) { compressed = ext; var n = path.length - ext.length - 1; ext = (path.substr(0, n).split('.').pop() || '').toLowerCase(); var m = base.length - ext.length - 1; base = base.substr(0, m); } else { compressed = false; } var binary = binaryExtList.includes(ext); return { path: path, name: name, ext: ext, base: base, dir: dir, compressed: compressed, binary: binary, protocol: protocol, query: query, src: file }; } exports.getFileInfo = getFileInfo; //# sourceMappingURL=file-info.js.map