// builtin import { readFile as _readFile } from 'node:fs' // external import accessible, { R_OK } from 'https://unpkg.com/@bevry/fs-accessible@^2.5.0/edition-deno/index.ts' import Errlop from 'https://unpkg.com/errlop@^8.4.0/edition-deno/index.ts' /** Read the contents of a file. */ export default async function read(path: string): Promise { // check accessible try { await accessible(path) } catch (err: any) { throw new Errlop(`unable to read the non-accessible file: ${path}`, err) } // check readable try { await accessible(path, R_OK) } catch (err: any) { throw new Errlop(`unable to read the non-readable file: ${path}`, err) } // attempt read return new Promise(function (resolve, reject) { _readFile(path, { encoding: 'utf8' }, function (err, contents) { if (err) { return reject( new Errlop( `failed to read the accessible and readable file: ${path}`, err ) ) } return resolve(contents) }) }) }