mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-23 19:49:56 +01:00
fs: add support for moving files
This commit is contained in:
committed by
Abdullah Atta
parent
69cb24149d
commit
7bb53a5e0c
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user