asSource

fun NSInputStream.asSource(): RawSource(source)

Returns RawSource that reads from an input stream.

Use RawSource.buffered to create a buffered source 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 inputStream = NSInputStream(data = data.toNSData())

val receivedData = inputStream.asSource().buffered().readByteArray()
assertContentEquals(data, receivedData) 
   //sampleEnd
}

Returns RawSource that reads from an input stream.

Use RawSource.buffered to create a buffered source 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 inputStream = ByteArrayInputStream(data)

val receivedData = inputStream.asSource().buffered().readByteArray()
assertContentEquals(data, receivedData) 
   //sampleEnd
}