Kotlin / kotlinx-io

Kotlin multiplatform I/O library
Apache License 2.0
1.28k stars 57 forks source link

Extensions for interop with platform-specific APIs #143

Open fzhinkin opened 1 year ago

fzhinkin commented 1 year ago

Currently (https://github.com/Kotlin/kotlinx-io/pull/136), kotlinx-io will only provide a bare minimum of extensions required for interop with Java-specific APIs:

At the moment, it seems like interaction with most other core Java APIs could be performed via java.io streams or java.nio channels and buffers, so it should be sufficient to cover most cases.

This issue opened to initiate a discussion on which extensions should be added additionally, not only for JVM but for other targets too.

fzhinkin commented 1 year ago

It's also worth revisiting names for JVM-specific Buffer extensions as some of them are confusing (compared to Source/Sink, where operations are more obvious, thanks to type names), like:

We may need to add some currently missing extensions and change the receiver of others to one of Buffer's interfaces - Sink or Source.

whyoleg commented 1 year ago

Some observations from looking on API doc:

Overall, there are following core functions to work with bulks of memory: readTo/readAtMostTo/write/copyTo/transferTo/transferFrom - ideally I think we should provide all of them for each primitive (where applicable), be it Buffer(and interfaces), ByteArray, ByteBuffer, InputStream/OutputStream and may be ByteChannel(ByteWriteChannel/ByteReadChannel). But then it can be too much :)