readUntil

suspend fun ByteReadChannel.readUntil(matchString: ByteString, writeChannel: ByteWriteChannel, limit: Long = Long.MAX_VALUE, ignoreMissing: Boolean = false): Long

Reads bytes from the ByteReadChannel until a specified sequence of bytes is encountered or the specified limit is reached.

This uses the KMP algorithm for finding the string match using a partial match table.

Return

The number of bytes read, not including the search string.

Parameters

matchString

The sequence of bytes to look for.

writeChannel

The channel to write the read bytes to.

limit

The maximum number of bytes to read before throwing an exception.

ignoreMissing

Whether to ignore the missing byteString and return the count of read bytes upon reaching the end of input.

See also

Throws

IOException

If the limit is exceeded or the byteString is not found and ignoreMissing is false.