Reads the content of a file at the specified path as a File.
The path of the file to read.
Read options specifying the 'blob' encoding.
A promise that resolves to an AsyncIOResult containing the file content as a File.
Reads the content of a file at the specified path as a string.
The path of the file to read.
Read options specifying the 'utf8' encoding.
A promise that resolves to an AsyncIOResult containing the file content as a string.
Reads the content of a file at the specified path as a readable stream. Useful for processing large files without loading them entirely into memory.
The path of the file to read.
Read options specifying the 'stream' encoding.
A promise that resolves to an AsyncIOResult containing a ReadableStream<Uint8Array>.
readFileSync for synchronous version (bytes only)
Reads the content of a file at the specified path as a Uint8Array (default).
The path of the file to read.
Optionaloptions: ReadOptions & { encoding?: "bytes" }Optional read options. Defaults to 'bytes' encoding.
A promise that resolves to an AsyncIOResult containing the file content as a Uint8Array.
readFileSync for synchronous version
Reads the content of a file at the specified path with the specified options. This overload accepts any ReadOptions and returns the union of all possible content types. Useful when the encoding is determined at runtime.
The path of the file to read.
Optionaloptions: ReadOptionsOptional read options.
A promise that resolves to an AsyncIOResult containing the file content.
readFileSync for synchronous version
// When encoding is dynamic
const encoding = getUserPreference(); // 'utf8' | 'bytes' | ...
(await readFile('/path/to/file.txt', { encoding }))
.inspect(content => {
// content type is ReadFileContent (union type)
if (typeof content === 'string') {
console.log('Text:', content);
} else if (content instanceof Uint8Array) {
console.log('Bytes:', content.length);
}
});
Reads the content of a file at the specified path with the specified options.
Template: T
The type of the content to read from the file.
Param: filePath
The path of the file to read.
Param: options
Optional read options.
Returns
A promise that resolves to an
AsyncIOResultcontaining the file content.