读取文件内容,可选地指定编码和返回类型。
返回内容的类型。
文件路径。
可选的读取选项。
包含文件内容的异步操作结果。
以 UTF-8 格式读取文件。
读取选项,指定编码为 'utf8'。
包含文件内容的字符串的异步操作结果。
1.0.0
const result = await readFile('/path/to/file.txt', { encoding: 'utf8' });if (result.isOk()) { console.log(result.unwrap());} Copy
const result = await readFile('/path/to/file.txt', { encoding: 'utf8' });if (result.isOk()) { console.log(result.unwrap());}
以二进制格式读取文件。
Optional
读取选项,指定编码为 'bytes'。
包含文件内容的 Uint8Array 的异步操作结果。
const result = await readFile('/path/to/file.txt', { encoding: 'bytes' });if (result.isOk()) { const bytes = result.unwrap(); console.log(decodeUtf8(bytes));} Copy
const result = await readFile('/path/to/file.txt', { encoding: 'bytes' });if (result.isOk()) { const bytes = result.unwrap(); console.log(decodeUtf8(bytes));}
读取文件内容。
文件的路径。
const result = await readFile('/path/to/file.txt');if (result.isOk()) { const bytes = result.unwrap(); console.log(decodeUtf8(bytes));} Copy
const result = await readFile('/path/to/file.txt');if (result.isOk()) { const bytes = result.unwrap(); console.log(decodeUtf8(bytes));}
读取文件内容,可选地指定编码和返回类型。
Template: T
返回内容的类型。
Param: filePath
文件路径。
Param: options
可选的读取选项。
Returns
包含文件内容的异步操作结果。