read(fileRegion:allocator:)

Read a FileRegion in NonBlockingFileIO’s private thread pool.

NonBlockingFileIO.swift:882
iOS
13+
macOS
10.15+
tvOS
13+
watchOS
6+
func read(fileRegion: FileRegion, allocator: ByteBufferAllocator) async throws -> ByteBuffer

Parameters

fileRegion

The file region to read.

allocator

A ByteBufferAllocator used to allocate space for the returned ByteBuffer.

Returns

ByteBuffer.

The returned ByteBuffer will not have less than the minimum of fileRegion.readableBytes and UInt32.max unless we hit end-of-file in which case the ByteBuffer will contain the bytes available to read.

This method will not use the file descriptor’s seek pointer which means there is no danger of reading from the same FileRegion in multiple threads.