Skip to content

Commit

Permalink
core: remove metadata file from .zip
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed Sep 9, 2024
1 parent 5038049 commit 4729844
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions packages/core/src/utils/note-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,22 @@ import { path } from "./path";
import { ZipFile } from "./zip-stream";

export const NOTE_DATA_FILENAME = "note.json";
export const METADATA_FILENAME = "metadata.json";
export const ATTACHMENTS_DIRECTORY_NAME = "attachments";

export type NoteFiles = {
files: Record<string, Uint8Array>;
hash: string;
};
export type PackageMetadata = {
version: string;
notes: string[];
};

export class NoteStream extends ReadableStream<ZipFile> {
constructor(storage: IStorage<Note>, report: (done: number) => void) {
const notes = storage.iterate();
const metadata: PackageMetadata = {
version: "1.0.0",
notes: []
};
let count = 0;

super({
async pull(controller) {
const { value: note, done } = await notes.next();
if (done) {
controller.enqueue({
path: METADATA_FILENAME,
data: new TextEncoder().encode(JSON.stringify(metadata))
});
await storage.clear();
return controller.close();
}
Expand All @@ -64,8 +52,7 @@ export class NoteStream extends ReadableStream<ZipFile> {
data: files[key]
});
}
metadata.notes.push(hash);
report(metadata.notes.length);
report(++count);
}
});
}
Expand Down

0 comments on commit 4729844

Please sign in to comment.