Skip to main content

readFile

method promises.FileHandle.readFile
Jump to headingFileHandle.readFile(options?: { encoding?: null | undefined; flag?: OpenMode | undefined; } | null): Promise<Buffer>

Asynchronously reads the entire contents of a file.

If options is a string, then it specifies the encoding.

The FileHandle has to support reading.

If one or more filehandle.read() calls are made on a file handle and then a filehandle.readFile() call is made, the data will be read from the current position till the end of the file. It doesn't always read from the beginning of the file.

Parameters Jump to heading

optional
Jump to headingoptions: { encoding?: null | undefined; flag?: OpenMode | undefined; } | null

Return Type Jump to heading

Promise<Buffer>

Fulfills upon a successful read with the contents of the file. If no encoding is specified (using options.encoding), the data is returned as a {Buffer} object. Otherwise, the data will be a string.

Jump to headingFileHandle.readFile(options: { encoding: BufferEncoding; flag?: OpenMode | undefined; } | BufferEncoding): Promise<string>

Asynchronously reads the entire contents of a file. The underlying file will not be closed automatically. The FileHandle must have been opened for reading.

Parameters Jump to heading

Jump to headingoptions: { encoding: BufferEncoding; flag?: OpenMode | undefined; } | BufferEncoding

An object that may contain an optional flag. If a flag is not provided, it defaults to 'r'.

Return Type Jump to heading

Promise<string>
Jump to headingFileHandle.readFile(options?:
(ObjectEncodingOptions & { flag?: OpenMode | undefined; })
| BufferEncoding
| null
): Promise<string | Buffer>

Asynchronously reads the entire contents of a file. The underlying file will not be closed automatically. The FileHandle must have been opened for reading.

Parameters Jump to heading

optional
Jump to headingoptions:
(ObjectEncodingOptions & { flag?: OpenMode | undefined; })
| BufferEncoding
| null

An object that may contain an optional flag. If a flag is not provided, it defaults to 'r'.

Return Type Jump to heading

Promise<string | Buffer>
Back to top