asSink
Returns RawSink that writes to an output stream.
Use RawSink.buffered to create a buffered sink from it.
Samples
import kotlinx.cinterop.*
import kotlinx.io.*
import platform.Foundation.*
import kotlin.test.Test
import kotlin.test.assertContentEquals
fun main() {
//sampleStart
val data = ByteArray(100) { it.toByte() }
val outputStream = NSOutputStream.outputStreamToMemory()
val sink = outputStream.asSink().buffered()
sink.write(data)
sink.flush()
val writtenData = outputStream.propertyForKey(NSStreamDataWrittenToMemoryStreamKey) as NSData
assertContentEquals(data, writtenData.toByteArray())
//sampleEnd
}
Returns RawSink that writes to an output stream.
Use RawSink.buffered to create a buffered sink from it.
Samples
import kotlinx.io.*
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
import kotlin.test.assertTrue
fun main() {
//sampleStart
val data = ByteArray(100) { it.toByte() }
val outputStream = ByteArrayOutputStream()
val sink = outputStream.asSink().buffered()
sink.write(data)
sink.flush()
assertContentEquals(data, outputStream.toByteArray())
//sampleEnd
}