peek

abstract fun peek(): Source(source)

Returns a new Source that can read data from this source without consuming it. The returned source becomes invalid once this source is next read or closed.

Peek could be used to lookahead and read the same data multiple times.

Throws

when the source is closed.

Samples

import kotlinx.io.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val source: Source = Buffer().also { it.writeString("hello world") }

val peek = source.peek().buffered()
assertEquals("hello", peek.readString(5))
peek.skip(1)
assertEquals("world", peek.readString(5))
assertTrue(peek.exhausted())

assertEquals("hello world", source.readString()) 
   //sampleEnd
}