kotlinx-io: Multiplatform I/O

预计阅读时间: 2 分钟

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

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 linear 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