Skip to content

Instance Method

readFile(at:chunkSize:offset:byteCount:)

Reads the contents of a file at the supplied path in chunks.
func readFile(at path: String, chunkSize: Int = NonBlockingFileIO.defaultChunkSize, offset: Int64? = nil, byteCount: Int? = nil) async throws -> FileIO.FileChunks

Parameters

path

Path to file on the disk.

chunkSize

Maximum size for the file data chunks.

offset

The offset to start reading from.

byteCount

The number of bytes to read from the file. If nil, the file will be read to the end.

Return Value

FileChunks containing the file data chunks.

Discussion

For try await chunk in try await req.fileio.readFile(at: “/path/to/file.txt”) { print(“chunk: (data)”) }

Warning

It’s the caller’s responsibility to close the file handle provided in FileIO.FileChunks when finished.