A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fs: add support for moving files
Abdullah Atta7bb53a5e0cec
diff --git a/packages/streamable-fs/index.ts b/packages/streamable-fs/index.tsindex 1ad865411..100e51535 100644--- a/packages/streamable-fs/index.ts+++ b/packages/streamable-fs/index.ts@@ -31,9 +31,12 @@ export class StreamableFS implements IStreamableFS {async createFile(filename: string,size: number,- type: string+ type: string,+ options?: { overwrite?: boolean }): Promise<FileHandle> {- if (await this.exists(filename)) throw new Error("File already exists.");+ const exists = await this.exists(filename);+ if (!options?.overwrite && exists) throw new Error("File already exists.");+ else if (options?.overwrite && exists) await this.deleteFile(filename);const file: File = {filename,@@ -69,6 +72,11 @@ export class StreamableFS implements IStreamableFS {return true;}+ async moveFile(source: FileHandle, dest: FileHandle) {+ await source.readable.pipeTo(dest.writeable);+ await source.delete();+ }+async clear(): Promise<void> {await this.storage.clear();}diff --git a/packages/streamable-fs/src/interfaces.ts b/packages/streamable-fs/src/interfaces.tsindex ef44b1de7..7869546f1 100644--- a/packages/streamable-fs/src/interfaces.ts+++ b/packages/streamable-fs/src/interfaces.ts@@ -21,10 +21,17 @@ import FileHandle from "./filehandle";import { File } from "./types";export interface IStreamableFS {- createFile(filename: string, size: number, type: string): Promise<FileHandle>;+ createFile(+ filename: string,+ size: number,+ type: string,+ options?: { overwrite?: boolean }+ ): Promise<FileHandle>;readFile(filename: string): Promise<FileHandle | undefined>;exists(filename: string): Promise<boolean>;deleteFile(filename: string): Promise<boolean>;+ list(): Promise<string[]>;+ moveFile(source: FileHandle, dest: FileHandle): Promise<void>;clear(): Promise<void>;}