Skip to content

Instance Method

readFile(at:chunkSize:onRead:)

Reads the contents of a file at the supplied path in chunks.
@preconcurrency func readFile(at path: String, chunkSize: Int = NonBlockingFileIO.defaultChunkSize, onRead: @escaping @Sendable (ByteBuffer) -> EventLoopFuture<Void>) -> EventLoopFuture<Void>

Parameters

path

Path to file on the disk.

chunkSize

Maximum size for the file data chunks.

onRead

Closure to be called sequentially for each file data chunk.

Return Value

Future that will complete when the file read is finished.

Discussion

try req.fileio.readFile(at: "/path/to/file.txt") { chunk in
    print("chunk: \(data)")
}.wait()