2 Star 13 Fork 1

KwooShung / Files

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
index.ts 732 Bytes
一键复制 编辑 原始数据 按行查看 历史
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;
1
https://gitee.com/kwooshung/Files.git
git@gitee.com:kwooshung/Files.git
kwooshung
Files
Files
main

搜索帮助