diff --git a/src/builders/Attachment.ts b/src/builders/Attachment.ts index 6bd252e..0b8bca7 100644 --- a/src/builders/Attachment.ts +++ b/src/builders/Attachment.ts @@ -2,8 +2,9 @@ import type { APIAttachment, RESTAPIAttachment } from 'discord-api-types/v10'; import { randomBytes } from 'node:crypto'; import path from 'node:path'; import { type UsingClient, throwError, type RawFile } from '..'; -import { promisesReadFile, promisesStat, type ImageResolvable, type ObjectToLower } from '../common'; +import type { ImageResolvable, ObjectToLower } from '../common'; import { Base } from '../structures/extra/Base'; +import { promises } from 'node:fs'; export interface AttachmentResolvableMap { url: string; @@ -197,12 +198,12 @@ export async function resolveAttachmentData( } case 'path': { const file = path.resolve(data as string); - const stats = await promisesStat(file); + const stats = await promises.stat(file); if (!stats.isFile()) return throwError( `The attachment type has been expressed as ${type.toUpperCase()} but cannot be resolved as one.`, ); - return { data: await promisesReadFile(file) }; + return { data: await promises.readFile(file) }; } case 'buffer': { if (Buffer.isBuffer(data)) return { data }; diff --git a/src/common/it/logger.ts b/src/common/it/logger.ts index c220439..74b49c3 100644 --- a/src/common/it/logger.ts +++ b/src/common/it/logger.ts @@ -1,7 +1,7 @@ -import { createWriteStream, existsSync, mkdirSync, type WriteStream } from 'node:fs'; +import { createWriteStream, existsSync, mkdirSync, promises, type WriteStream } from 'node:fs'; import { join } from 'node:path'; import { bgBrightWhite, black, bold, brightBlack, cyan, gray, italic, red, stripColor, yellow } from './colors'; -import { MergeOptions, promisesReaddir, promisesUnlink } from './utils'; +import { MergeOptions } from './utils'; export enum LogLevels { Debug = 0, Info = 1, @@ -51,9 +51,9 @@ export class Logger { } static async clearLogs() { - for (const i of await promisesReaddir(join(process.cwd(), Logger.dirname))) { + for (const i of await promises.readdir(join(process.cwd(), Logger.dirname), { withFileTypes: true })) { if (this.streams[i.name]) await new Promise(res => this.streams[i.name]!.close(res)); - await promisesUnlink(join(process.cwd(), Logger.dirname, i.name)).catch(() => {}); + await promises.unlink(join(process.cwd(), Logger.dirname, i.name)).catch(() => {}); delete this.streams[i.name]; } } diff --git a/src/common/it/utils.ts b/src/common/it/utils.ts index 2652e35..a13cbb6 100644 --- a/src/common/it/utils.ts +++ b/src/common/it/utils.ts @@ -1,5 +1,4 @@ -import type fs from 'node:fs'; -import { type Dirent, readFile, readdir, stat, unlink } from 'node:fs'; +import { promises } from 'node:fs'; import { basename, join } from 'node:path'; import { EmbedColors, type ColorResolvable, type Logger, type ObjectToLower, type ObjectToSnake } from '..'; @@ -115,7 +114,7 @@ export class BaseHandler { protected async getFiles(dir: string) { const files: string[] = []; - for (const i of await promisesReaddir(dir)) { + for (const i of await promises.readdir(dir, { withFileTypes: true })) { if (i.isDirectory()) { files.push(...(await this.getFiles(join(dir, i.name)))); } else { @@ -282,40 +281,3 @@ export function isCloudfareWorker() { //@ts-expect-error return process.platform === 'browser'; } - -//cloudfare support -export function promisesReadFile(file: string) { - return new Promise((res, rej) => - readFile(file, (err, result) => { - if (err) return rej(err); - res(result); - }), - ); -} - -export function promisesUnlink(file: string) { - return new Promise((res, rej) => - unlink(file, err => { - if (err) return rej(err); - res(); - }), - ); -} - -export function promisesStat(file: string) { - return new Promise((res, rej) => - stat(file, (err, result) => { - if (err) return rej(err); - res(result); - }), - ); -} - -export function promisesReaddir(file: string) { - return new Promise((res, rej) => - readdir(file, { withFileTypes: true }, (err, result) => { - if (err) return rej(err); - res(result); - }), - ); -}