writeAvailable

expect abstract suspend fun writeAvailable(src: ByteArray, offset: Int, length: Int): Int

Writes as much as possible and only suspends if buffer is full


expect abstract suspend fun writeAvailable(src: ChunkBuffer): Int
actual abstract suspend fun writeAvailable(src: ByteArray, offset: Int, length: Int): Int

Writes as much as possible and only suspends if buffer is full


actual abstract suspend fun writeAvailable(src: ChunkBuffer): Int
abstract suspend fun writeAvailable(src: ByteBuffer): Int
actual abstract suspend fun writeAvailable(src: ChunkBuffer): Int


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

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

Warning: it is not guaranteed that all of remaining bytes will be represented as a single byte buffer eg: it could be 4 bytes available for write but the provided byte buffer could have only 2 remaining bytes: in this case you have to invoke write 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 write, should be positive

block

to be invoked when at least min bytes free capacity available


actual abstract suspend fun writeAvailable(src: ByteArray, offset: Int, length: Int): Int

Writes as much as possible and only suspends if buffer is full

abstract suspend fun writeAvailable(src: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int): Int
abstract suspend fun writeAvailable(src: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Long): Int
actual abstract suspend fun writeAvailable(src: ByteArray, offset: Int, length: Int): Int
actual abstract suspend fun writeAvailable(src: ChunkBuffer): Int

Writes as much as possible and only suspends if buffer is full