Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: lazily load zip/unzip streams

Abdullah Atta03a2a2f9ccf8
diff --git a/apps/web/src/common/export.ts b/apps/web/src/common/export.ts
index e35910a12..21d3e4822 100644
--- a/apps/web/src/common/export.ts
+++ b/apps/web/src/common/export.ts
@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { TaskManager } from "./task-manager";
-import { createZipStream } from "../utils/streams/zip-stream";
import { createWriteStream } from "../utils/stream-saver";
import { FilteredSelector } from "@notesnook/core";
import { Note } from "@notesnook/core";
@@ -90,6 +89,8 @@ export async function exportNotes(
title: strings.exportingNotes(),
subtitle: strings.exportingNotesDesc(),
action: async (report) => {
+ const { createZipStream } = await import("../utils/streams/zip-stream");
+
const errors: Error[] = [];
const exportStream = new ExportStream(report, (e) => errors.push(e));
await fromAsyncIterator(
@@ -170,6 +171,7 @@ export async function exportNote(
);
if (hasAttachments) {
+ const { createZipStream } = await import("../utils/streams/zip-stream");
await stream
.pipeThrough(createZipStream())
.pipeTo(
diff --git a/apps/web/src/common/index.ts b/apps/web/src/common/index.ts
index 1b5ef99f8..8a5be0991 100644
--- a/apps/web/src/common/index.ts
+++ b/apps/web/src/common/index.ts
@@ -31,9 +31,7 @@ import { PATHS } from "@notesnook/desktop";
import { TaskManager } from "./task-manager";
import { EVENTS } from "@notesnook/core";
import { createWritableStream } from "./desktop-bridge";
-import { createZipStream, ZipFile } from "../utils/streams/zip-stream";
import { FeatureDialog, FeatureKeys } from "../dialogs/feature-dialog";
-import { ZipEntry, createUnzipIterator } from "../utils/streams/unzip-stream";
import { User } from "@notesnook/core";
import { LegacyBackupFile } from "@notesnook/core";
import { useEditorStore } from "../stores/editor-store";
@@ -45,6 +43,9 @@ import { Cipher, SerializedKey } from "@notesnook/crypto";
import { ChunkedStream } from "../utils/streams/chunked-stream";
import { isFeatureSupported } from "../utils/feature-check";
import { strings } from "@notesnook/intl";
+import { ABYTES, streamablefs } from "../interfaces/fs";
+import { type ZipEntry } from "../utils/streams/unzip-stream";
+import { ZipFile } from "../utils/streams/zip-stream";
export const CREATE_BUTTON_MAP = {
notes: {
@@ -121,11 +122,11 @@ export async function createBackup(
title: strings.backingUpData(mode),
subtitle: strings.backingUpDataWait(),
action: async (report) => {
+ const { createZipStream } = await import("../utils/streams/zip-stream");
const writeStream = await createWritableStream(filePath);
await new ReadableStream<ZipFile>({
start() {},
async pull(controller) {
- const { streamablefs } = await import("../interfaces/fs");
for await (const output of db.backup!.export({
type: "web",
encrypt: encryptedBackups,
@@ -217,6 +218,10 @@ export async function restoreBackupFile(backupFile: File) {
subtitle: strings.restoringBackupDesc(),
type: "modal",
action: async (report) => {
+ const { createUnzipIterator } = await import(
+ "../utils/streams/unzip-stream"
+ );
+
let cachedPassword: string | undefined = undefined;
let cachedKey: string | undefined = undefined;
// const { read, totalFiles } = await Reader(backupFile);
@@ -282,7 +287,6 @@ export async function restoreBackupFile(backupFile: File) {
});
await db.initCollections();
- const { ABYTES, streamablefs } = await import("../interfaces/fs");
let current = 0;
for (const entry of attachments) {
const hash = entry.name.replace("attachments/", "");
diff --git a/apps/web/src/stores/attachment-store.ts b/apps/web/src/stores/attachment-store.ts
index 0a010978c..d9c8243fc 100644
--- a/apps/web/src/stores/attachment-store.ts
+++ b/apps/web/src/stores/attachment-store.ts
@@ -25,7 +25,6 @@ import { useStore as useNoteStore } from "./note-store";
import { checkAttachment } from "../common/attachments";
import { showToast } from "../utils/toast";
import { AttachmentStream } from "../utils/streams/attachment-stream";
-import { createZipStream } from "../utils/streams/zip-stream";
import { createWriteStream } from "../utils/stream-saver";
import { Attachment } from "@notesnook/core";
import { TaskManager } from "../common/task-manager";
@@ -63,6 +62,8 @@ class AttachmentStore extends BaseStore<AttachmentStore> {
this.set({ status: { current, total: ids.length } });
}
);
+
+ const { createZipStream } = await import("../utils/streams/zip-stream");
await attachmentStream
.pipeThrough(createZipStream(abortController.signal))
.pipeTo(
diff --git a/apps/web/src/utils/importer.ts b/apps/web/src/utils/importer.ts
index 2a973f330..cbd81195a 100644
--- a/apps/web/src/utils/importer.ts
+++ b/apps/web/src/utils/importer.ts
@@ -29,9 +29,12 @@ import {
NOTE_DATA_FILENAME
} from "@notesnook-importer/core/dist/src/utils/note-stream";
import { path } from "@notesnook-importer/core/dist/src/utils/path";
+import { type ZipEntry } from "./streams/unzip-stream";
import { hashBuffer, writeEncryptedFile } from "../interfaces/fs";
export async function* importFiles(zipFiles: File[]) {
+ const { createUnzipIterator } = await import("./streams/unzip-stream");
+
for (const zip of zipFiles) {
let count = 0;
let filesRead = 0;
diff --git a/apps/web/src/utils/logger.ts b/apps/web/src/utils/logger.ts
index 1634e8ca2..90d679e76 100644
--- a/apps/web/src/utils/logger.ts
+++ b/apps/web/src/utils/logger.ts
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { initialize, logger as _logger, logManager } from "@notesnook/core";
import { LogMessage, NoopLogger, format } from "@notesnook/logger";
-import { ZipFile, createZipStream } from "./streams/zip-stream";
+import { ZipFile } from "./streams/zip-stream";
import { createWriteStream } from "./stream-saver";
import { sanitizeFilename } from "@notesnook/common";
import { createDialect } from "../common/sqlite";
@@ -57,6 +57,7 @@ async function initializeLogger() {
async function downloadLogs() {
if (!logManager) return;
+ const { createZipStream } = await import("./streams/zip-stream");
const allLogs = await logManager.get();
let i = 0;
const textEncoder = new TextEncoder();