mySink.use { ktorHttpClient.prepareGet(url).execute { httpResponse -> val channel = httpResponse.bodyAsChannel() // TODO ideally there would just be a way to get a Source from ktor and write Source->Sink while (!channel.isClosedForRead) { val packet = channel.readRemaining(8192L) while (!packet.isEmpty) { val bytes = packet.readBytes() mySink.write(bytes) } } mySink.flush() } }