substring

fun ByteString.substring(startIndex: Int = 0, kapacity: Kapacity): ByteString

Returns a new ByteString containing a subset of bytes from this instance, starting at the startIndex and capturing up to the specified kapacity.

Warning on Bounds: Because ByteString relies on Int indexing, extraction is safely bounded to Int.MAX_VALUE- 8 (approximately 2.14 GB). The target end index is clamped to prevent IndexOutOfBoundsException if the capacity exceeds the available data.

Return

A new ByteString containing the requested chunk of data.

Parameters

startIndex

The index to begin the extraction. Defaults to 0.

kapacity

The total amount of data to capture in the new ByteString.