Update ImportExportModal.js

This commit is contained in:
Mitchell McCaffrey 2021-02-07 22:20:27 +11:00
parent 23b0432bb2
commit 93a8563210

View File

@ -4,8 +4,7 @@ import * as streamSaver from "streamsaver";
import * as streamPonyfill from "web-streams-polyfill/ponyfill"; import * as streamPonyfill from "web-streams-polyfill/ponyfill";
import * as Comlink from "comlink"; import * as Comlink from "comlink";
// Polyfill blob to get use to Blob.stream() on unsupported browsers (Safari) // Polyfill blob to get use to Blob.stream() on unsupported browsers (Safari)
// eslint-disable-next-line no-unused-vars import "blob-polyfill";
import { Blob } from "blob-polyfill";
import Modal from "../components/Modal"; import Modal from "../components/Modal";
import LoadingOverlay from "../components/LoadingOverlay"; import LoadingOverlay from "../components/LoadingOverlay";
@ -67,25 +66,12 @@ function ImportDatabaseModal({ isOpen, onRequestClose }) {
fileStreamRef.current = fileStream; fileStreamRef.current = fileStream;
const readableStream = blob.stream(); const readableStream = blob.stream();
if (window.WritableStream && readableStream.pipeTo) { try {
readableStream.pipeTo(fileStream); await readableStream.pipeTo(fileStream);
backgroundTaskRunningRef.current = false; } catch (error) {
} else { console.error(error);
// Fallback when no writableStream and pipeTo is available (Safari)
const writer = fileStream.getWriter();
const reader = readableStream.getReader();
async function pump() {
const res = await reader.read();
if (res.done) {
writer.close();
} else {
await writer.write(res.value);
await pump();
}
}
await pump();
backgroundTaskRunningRef.current = false;
} }
backgroundTaskRunningRef.current = false;
fileStreamRef.current = null; fileStreamRef.current = null;
} }