Skip to content

Commit

Permalink
feat: add deleteDir and readDir methods to FileStorageLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
eamon0989 committed Oct 27, 2022
1 parent 03af811 commit f32db73
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/file-storage/src/file-storage-fs.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
writeFile,
WriteFileOptions,
} from 'fs';
import { readdir, rm } from 'fs/promises';
import { resolve as resolvePath } from 'path';
import { Readable, Writable } from 'stream';
import { promisify } from 'util';
Expand Down Expand Up @@ -139,4 +140,16 @@ export class FileStorageLocal implements FileStorage {
unlink(fileName, (err) => (err && err.message === 'EENOENT' ? reject(err) : resolve(true))),
);
}

async deleteDir(args: { dirPath: string; request?: Request }): Promise<void> {
const { dirPath, request } = args;
const dirName = await this.transformFilePath(dirPath, request);
return await rm(dirName, { recursive: true, force: true });
}

async readDir(args: { dirPath: string }): Promise<string[]> {
const { dirPath } = args;
const transformedDirPath = await this.transformFilePath(dirPath);
return await readdir(transformedDirPath);
}
}

0 comments on commit f32db73

Please sign in to comment.