readData(ofMinLength:maxLength:timeout:completionHandler:)
Asynchronously reads a number of bytes from the stream, and calls a handler upon completion.
Declaration
func readData(ofMinLength minBytes: Int, maxLength maxBytes: Int, timeout: TimeInterval, completionHandler: @escaping @Sendable (Data?, Bool, (any Error)?) -> Void)func readData(ofMinLength minBytes: Int, maxLength maxBytes: Int, timeout: TimeInterval) async throws -> (Data?, Bool)Parameters
- minBytes:
The minimum number of bytes to read.
- maxBytes:
The maximum number of bytes to read.
- timeout:
A timeout for reading bytes. If the read is not completed within the specified interval, the read is canceled and the
completionHandleris called with an error. Pass0to prevent a read from timing out. - completionHandler:
The completion handler to call when all bytes are read, or an error occurs. This handler is executed on the delegate queue.
This completion handler takes the following parameters:
dataThe data read from the stream.
atEOFWhether or not the stream reached end-of-file (EOF), such that no more data can be read.
errorAn error object that indicates why the read failed, or
nilif the read was successful.