minigame-std
    Preparing search index...

    Function readFileSync

    • 以 UTF-8 格式读取文件。

      Parameters

      • filePath: string

        文件路径。

      • options: fs.ReadOptions & { encoding: "utf8" }

        读取选项,指定编码为 'utf8'。

      Returns IOResult<string>

      包含文件内容的字符串的操作结果。

      1.1.0

      const result = readFileSync('/path/to/file.txt', { encoding: 'utf8' });
      if (result.isOk()) {
      console.log(result.unwrap());
      }
    • 以二进制格式读取文件。

      Parameters

      • filePath: string

        文件路径。

      • Optionaloptions: fs.ReadOptions & { encoding: "bytes" }

        读取选项,指定编码为 'bytes'。

      Returns IOResult<Uint8Array<ArrayBuffer>>

      包含文件内容的 Uint8Array 的操作结果。

      1.1.0

      const result = readFileSync('/path/to/file.txt', { encoding: 'bytes' });
      if (result.isOk()) {
      const bytes = result.unwrap();
      console.log(decodeUtf8(bytes));
      }
    • readFile 的同步版本,读取文件内容。

      Parameters

      • filePath: string

        文件的路径。

      • Optionaloptions: fs.ReadOptions

        可选的读取选项。

      Returns IOResult<fs.ReadFileContent>

      包含文件内容的操作结果。

      1.1.0

      const result = readFileSync('/path/to/file.txt');
      if (result.isOk()) {
      const bytes = result.unwrap();
      console.log(decodeUtf8(bytes));
      }