Buffer 路径


使用 <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:

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();
}