缓冲区路径
【Buffer paths】
使用 <Buffer> 指定的路径主要在某些将文件路径视为不透明字节序列的 POSIX 操作系统上很有用。在这样的系统上,一个文件路径中可能包含使用多种字符编码的子序列。与字符串路径一样,<Buffer> 路径也可以是相对的或绝对的:
【Paths specified using a <Buffer> are useful primarily on certain POSIX operating systems that treat file paths as opaque byte sequences. On such systems, it is possible for a single file path to contain sub-sequences that use multiple character encodings. As with string paths, <Buffer> paths may be relative or absolute:】
在 POSIX 上使用绝对路径的示例:
【Example using an absolute path on POSIX:】
import { open } from 'node:fs/promises';
import { Buffer } from 'node:buffer';
let fd;
try {
fd = await open(Buffer.from('/open/some/file.txt'), 'r');
// Do something with the file
} finally {
await fd?.close();
}