代码拉取完成,页面将自动刷新
import fs from 'fs/promises';
import normalize from '@/normalize';
import exists from '@/exists';
/**
* 读取指定路径的文件内容 (read the contents of the specified path file)
* @param {string} filePath 要读取的文件路径 (the file path to read)
* @param {BufferEncoding} [encoding='utf8'] 文件的编码格式,默认为 utf8 (the encoding format of the file, default is utf8)
* @returns {Promise<string>} 返回文件内容。
*/
const read = async (filePath: string, encoding: BufferEncoding = 'utf8'): Promise<string> => {
try {
if (await exists(filePath)) {
return await fs.readFile(normalize(filePath), encoding);
}
return '';
} catch {
return '';
}
};
export default read;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。