toNSData

fun ByteString.toNSData(): <Error class: unknown class>(source)

Returns a new NSData instance initialized with bytes copied from this ByteString.

Samples

import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.UnsafeNumber
import kotlinx.io.bytestring.*
import platform.Foundation.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val originalByteString: ByteString = "Compress me, please!".encodeToByteString()

val compressedNSData: NSData = originalByteString.toNSData().compressedDataUsingAlgorithm(
    algorithm = NSDataCompressionAlgorithmZlib,
    error = null
)!!

val compressedByteString: ByteString = compressedNSData.toByteString()
assertEquals("73cecf2d284a2d2e56c84dd55128c8494d2c4e550400", compressedByteString.toHexString())
// If there's no zlib-flate on your path, you can test it using:
// zlib.decompress(binascii.unhexlify("73cecf2d284a2d2e56c84dd55128c8494d2c4e550400"), -15) 
   //sampleEnd
}