Skip to content

Commit

Permalink
✨ Use fs/promises functions instead of promisify (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyhpy authored Aug 6, 2021
1 parent eafb122 commit 391bc38
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { SnowflakeUtil, Intents } from 'discord.js';
import nodeFetch from 'node-fetch';
import { sep } from 'path';

import { existsSync, mkdirSync, readdir, statSync, unlinkSync, writeFile } from 'fs';
import { promisify } from 'util';
const writeFileAsync = promisify(writeFile);
const readdirAsync = promisify(readdir);
import { existsSync, mkdirSync, statSync, unlinkSync } from 'fs';
import { writeFile, readdir } from 'fs/promises';

import * as createMaster from './create';
import * as loadMaster from './load';
Expand All @@ -24,7 +22,7 @@ if (!existsSync(backups)) {
*/
const getBackupData = async (backupID: string) => {
return new Promise<BackupData>(async (resolve, reject) => {
const files = await readdirAsync(backups); // Read "backups" directory
const files = await readdir(backups); // Read "backups" directory
// Try to get the json file
const file = files.filter((f) => f.split('.').pop() === 'json').find((f) => f === `${backupID}.json`);
if (file) {
Expand Down Expand Up @@ -145,7 +143,7 @@ export const create = async (
? JSON.stringify(backupData, null, 4)
: JSON.stringify(backupData);
// Save the backup
await writeFileAsync(`${backups}${sep}${backupData.id}.json`, backupJSON, 'utf-8');
await writeFile(`${backups}${sep}${backupData.id}.json`, backupJSON, 'utf-8');
}
// Returns ID
resolve(backupData);
Expand Down Expand Up @@ -223,7 +221,7 @@ export const remove = async (backupID: string) => {
* Returns the list of all backup
*/
export const list = async () => {
const files = await readdirAsync(backups); // Read "backups" directory
const files = await readdir(backups); // Read "backups" directory
return files.map((f) => f.split('.')[0]);
};

Expand Down

0 comments on commit 391bc38

Please sign in to comment.