asOutputStream
Returns an output stream that writes to this sink. Closing the stream will also close this sink.
Returns an output stream that writes to this sink. Closing the stream will also close this sink.
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.* fun main() { //sampleStart val buffer = Buffer() val data = ByteArray(100) { it.toByte() } GZIPOutputStream(buffer.asOutputStream()).use { it.write(data) } val decodedData = GZIPInputStream(buffer.asInputStream()).use { it.readBytes() } assertContentEquals(data, decodedData) //sampleEnd }
xxxxxxxxxx
val buffer = Buffer()
val data = ByteArray(100) { it.toByte() }
GZIPOutputStream(buffer.asOutputStream()).use {
it.write(data)
}
val decodedData = GZIPInputStream(buffer.asInputStream()).use {
it.readBytes()
}
assertContentEquals(data, decodedData)