kotlinx-io: Multiplatform I/O

Estimated reading time: 2 minutes

The official multiplatform asynchronous I/O for Kotlin. It depends on kotlinx.coroutines and kotlinx.atomicfu.

Kotlin provides two killer features: multiplatform projects (including common projects) and coroutines. But multiplatform doesn’t provide any special functionality, only let’s you to use the exposed APIs from each platform. And coroutines are low-level too.

This project exposes common functionality for doing I/O in a way that works in all the targets and uses coroutines to expose a non-blocking API that can be written as plain synchronous code easily.

Kotlinx-io is OpenSource and you can find it at GitHub: https://github.com/Kotlin/kotlinx-io

Encoding:

  • Charset - Decoding/encoding Strings from/to ByteArrays.
  • ByteOrder - To express which Endian (Little or Big) to use for converting numbers from/to octets.

I/O:

  • Byte Channels - Asynchronous byte streams without seeking support, consumed once.
  • Input/Output - Interfaces with the functionality exposed by IoBuffers and Packets.
  • IoBuffer - A seekable View of a fixed buffer/memory chunk similar to Java’s ByteBuffer.
  • Packets - Synchronous streams without seeking support, constructed once with a potentially unknown size, consumed once.

Tools:

  • ObjectPool - Generic, lock-free and concurrent ObjectPool.

Platforms:

  • JVM - Tools for conversions between CIO and NIO Buffers, and Java Streams.
  • JavaScript - Tools for TypedArrays, WebSockets, MessageEvent and XMLHttpRequest.
  • Native - No special APIs to interact with K/N primitives yet