From 02f15d573ac9f98aa145706a0beaec2d6c2b3fbd Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Fri, 25 Jun 2021 11:52:26 +0530 Subject: [PATCH] Refactor --- src/utils/exportUtils/Exporter.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index 028b5c808e..2401bce0c8 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -48,15 +48,18 @@ export default abstract class Exporter { protected async downloadZIP() { const filename = `matrix-export-${formatFullDateNoDay(new Date())}.zip`; - //Support for firefox browser + + // Support for older browsers streamSaver.WritableStream = ponyfill.WritableStream - //Create a writable stream to the directory + + // Create a writable stream to the directory this.fileStream = streamSaver.createWriteStream(filename); + console.info("Generating a ZIP..."); + this.writer = this.fileStream.getWriter(); const files = this.files; - console.info("Generating a ZIP..."); const readableZipStream = streamToZIP({ start(ctrl) { for (const file of files) ctrl.enqueue(file); @@ -79,8 +82,8 @@ export default abstract class Exporter { } protected async abortExport(): Promise { - if (this.fileStream) await this.fileStream.abort(); - if (this.writer) await this.writer.abort(); + await this.fileStream?.abort(); + await this.writer?.abort(); } protected async pumpToFileStream(reader: ReadableStreamDefaultReader) {