Skip to content

Commit

Permalink
feat: 🎸 add rmdirSync() method
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 20, 2023
1 parent a1674e4 commit 59ccf3c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions demo/fsa/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const demo = async (dir: fsa.IFileSystemDirectoryHandle) => {
console.log('renameSync() - can move a file');
fs.renameSync('/cool (Copy).txt', '/dir/very-cool.txt');
strictEqual(fs.readFileSync('/dir/very-cool.txt', 'utf8'), 'worlds!');

console.log('rmdirSync() - can remove an empty directory');
await fs.promises.mkdir('/to-be-deleted');
strictEqual(fs.existsSync('/to-be-deleted'), true);
fs.rmdirSync('/to-be-deleted');
strictEqual(fs.existsSync('/to-be-deleted'), false);
};

const main = async () => {
Expand Down
7 changes: 6 additions & 1 deletion src/fsa-to-node/FsaNodeFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,12 @@ export class FsaNodeFs extends FsaNodeCore implements FsCallbackApi, FsSynchrono
adapter.call('move', {src: srcFilename, dst: destFilename});
};

public readonly rmdirSync: FsSynchronousApi['rmdirSync'] = (path: misc.PathLike, opts?: opts.IRmdirOptions): void => {
const filename = pathToFilename(path);
const adapter = this.getSyncAdapter();
adapter.call('rmdir', {path: filename, opts});
};

public readonly ftruncateSync: FsSynchronousApi['ftruncateSync'] = notSupported;
public readonly linkSync: FsSynchronousApi['linkSync'] = notSupported;
public readonly mkdirSync: FsSynchronousApi['mkdirSync'] = notSupported;
Expand All @@ -867,7 +873,6 @@ export class FsaNodeFs extends FsaNodeCore implements FsCallbackApi, FsSynchrono
public readonly readlinkSync: FsSynchronousApi['readlinkSync'] = notSupported;
public readonly readSync: FsSynchronousApi['readSync'] = notSupported;
public readonly realpathSync: FsSynchronousApi['realpathSync'] = notSupported;
public readonly rmdirSync: FsSynchronousApi['rmdirSync'] = notSupported;
public readonly rmSync: FsSynchronousApi['rmSync'] = notSupported;
public readonly symlinkSync: FsSynchronousApi['symlinkSync'] = notSupported;
public readonly truncateSync: FsSynchronousApi['truncateSync'] = notSupported;
Expand Down
1 change: 1 addition & 0 deletions src/fsa-to-node/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface FsaNodeSyncAdapterApi {
appendFile(req: { filename: string; data: Uint8Array; opts?: opts.IAppendFileOptions }): void;
copy(req: { src: string; dst: string, flags?: number }): void;
move(req: { src: string; dst: string }): void;
rmdir(req: { path: string; opts?: opts.IRmdirOptions }): void;
}

export interface FsaNodeSyncAdapter {
Expand Down
3 changes: 3 additions & 0 deletions src/fsa-to-node/worker/FsaNodeSyncWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,8 @@ export class FsaNodeSyncWorker {
move: async ({ src, dst }): Promise<void> => {
await this.fs.promises.rename(src, dst);
},
rmdir: async ({ path, opts }): Promise<void> => {
await this.fs.promises.rmdir(path, opts);
},
};
}

0 comments on commit 59ccf3c

Please sign in to comment.