readAvailable

expect abstract suspend fun readAvailable(dst: ByteArray, offset: Int, length: Int): Int

Reads all available bytes to dst buffer and returns immediately or suspends if no bytes available

Return

number of bytes were read or -1 if the channel has been closed


expect abstract suspend fun readAvailable(dst: ChunkBuffer): Int
abstract suspend fun readAvailable(dst: ArrayBuffer, offset: Int, length: Int): Int
actual abstract suspend fun readAvailable(dst: ChunkBuffer): Int


actual abstract suspend fun readAvailable(dst: ByteArray, offset: Int, length: Int): Int

Reads all available bytes to dst buffer and returns immediately or suspends if no bytes available

Return

number of bytes were read or -1 if the channel has been closed

abstract fun readAvailable(min: Int = 1, block: (ByteBuffer) -> Unit): Int

Invokes block if it is possible to read at least min byte providing byte buffer to it so lambda can read from the buffer up to ByteBuffer.available bytes. If there are no min bytes available then the invocation returns 0.

Warning: it is not guaranteed that all of available bytes will be represented as a single byte buffer eg: it could be 4 bytes available for read but the provided byte buffer could have only 2 available bytes: in this case you have to invoke read again (with decreased min accordingly).

Return

number of consumed bytes or -1 if the block wasn't executed.

Parameters

min

amount of bytes available for read, should be positive

block

to be invoked when at least min bytes available


abstract suspend fun readAvailable(dst: ByteBuffer): Int
actual abstract suspend fun readAvailable(dst: ChunkBuffer): Int


actual abstract suspend fun readAvailable(dst: ByteArray, offset: Int, length: Int): Int

Reads all available bytes to dst buffer and returns immediately or suspends if no bytes available

Return

number of bytes were read or -1 if the channel has been closed

abstract fun readAvailable(min: Int, block: (Buffer) -> Unit): Int

Invokes block if it is possible to read at least min byte providing buffer to it so lambda can read from the buffer up to Buffer.readRemaining bytes. If there are no min bytes available then the invocation returns -1.

Warning: it is not guaranteed that all of available bytes will be represented as a single byte buffer eg: it could be 4 bytes available for read but the provided byte buffer could have only 2 available bytes: in this case you have to invoke read again (with decreased min accordingly).

Return

number of consumed bytes or -1 if the block wasn't executed.

Parameters

min

amount of bytes available for read, should be positive

block

to be invoked when at least min bytes available


abstract suspend fun readAvailable(dst: CPointer<ByteVar>, offset: Int, length: Int): Int
abstract suspend fun readAvailable(dst: CPointer<ByteVar>, offset: Long, length: Long): Int
actual abstract suspend fun readAvailable(dst: ByteArray, offset: Int, length: Int): Int
actual abstract suspend fun readAvailable(dst: ChunkBuffer): Int

Reads all available bytes to dst buffer and returns immediately or suspends if no bytes available

Return

number of bytes were read or -1 if the channel has been closed