minigame-std
    Preparing search index...

    Function readFile

    读取文件内容,可选地指定编码和返回类型。

    返回内容的类型。

    文件路径。

    可选的读取选项。

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

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

      Parameters

      • filePath: string

        文件路径。

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

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

      Returns AsyncIOResult<string>

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

      1.0.0

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

      Parameters

      • filePath: string

        文件路径。

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

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

      Returns AsyncIOResult<Uint8Array<ArrayBuffer>>

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

      1.0.0

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

      Parameters

      • filePath: string

        文件的路径。

      • Optionaloptions: fs.ReadOptions

        可选的读取选项。

      Returns AsyncIOResult<fs.ReadFileContent>

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

      1.0.0

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