Browse Source

async zip

JonStargaryen 4 years ago
parent
commit
9cbdada13e
3 changed files with 7 additions and 7 deletions
  1. 4 4
      src/viewer/helpers/export.ts
  2. 1 1
      src/viewer/index.ts
  3. 2 2
      src/viewer/ui/export.tsx

+ 4 - 4
src/viewer/helpers/export.ts

@@ -4,7 +4,7 @@ import { PluginStateObject } from 'molstar/lib/mol-plugin-state/objects';
 import { StructureSelection, Structure } from 'molstar/lib/mol-model/structure';
 import { CifExportContext, encode_mmCIF_categories } from 'molstar/lib/mol-model/structure/export/mmcif';
 import { utf8ByteCount, utf8Write } from 'molstar/lib/mol-io/common/utf8';
-import { zip } from 'molstar/lib/mol-util/zip/zip';
+import { Zip } from 'molstar/lib/mol-util/zip/zip';
 import { getFormattedTime } from 'molstar/lib/mol-util/date';
 import { download } from 'molstar/lib/mol-util/download';
 import { CustomPropertyDescriptor } from 'molstar/lib/mol-model/custom-property';
@@ -91,8 +91,8 @@ export function encodeStructureData(plugin: PluginContext): { [k: string]: Uint8
     return content;
 }
 
-export function downloadAsZipFile(content: { [k: string]: Uint8Array }) {
+export async function downloadAsZipFile(plugin: PluginContext, content: { [k: string]: Uint8Array }) {
     const filename = `mol-star_download_${getFormattedTime()}.zip`;
-    const buf = zip(content);
-    download(new Blob([buf]), filename);
+    const buf = await plugin.runTask(Zip(content));
+    download(new Blob([buf], { type : 'application/zip' }), filename);
 }

+ 1 - 1
src/viewer/index.ts

@@ -266,7 +266,7 @@ export class Viewer {
 
     exportLoadedStructures() {
         const content = encodeStructureData(this.plugin);
-        downloadAsZipFile(content);
+        return downloadAsZipFile(this.plugin, content);
     }
 
     pluginCall(f: (plugin: PluginContext) => void){

+ 2 - 2
src/viewer/ui/export.tsx

@@ -27,9 +27,9 @@ export class ExportControls extends CollapsableControls {
 }
 
 class CoordinatesExportControls extends PluginUIComponent {
-    download = () => {
+    download = async () => {
         const content = encodeStructureData(this.plugin);
-        downloadAsZipFile(content);
+        await downloadAsZipFile(this.plugin, content);
     }
 
     render() {