import fs from 'fs' import axios from 'axios' export default { async getUrlBuffer(url: string) { const { data } = await axios({ method: 'GET', url, responseType: 'arraybuffer', }) return data }, async checkAndCreateDirectory(dirPath: string) { try { if (!(await this.doesDirectoryExist(dirPath))) await fs.promises.mkdir(dirPath) return true } catch (err) { if (err.code == 'EEXIST') return true throw err } }, async doesDirectoryExist(filePath: string) { try { const stats = await fs.promises.stat(filePath) return stats.isDirectory() } catch (e) { return false } }, }