kotlinx-io icon indicating copy to clipboard operation
kotlinx-io copied to clipboard

Add some useful extensions

Open e5l opened this issue 6 years ago • 4 comments

Let's consider to add some useful extensions:

  • [x] fun String.toByteReadChannel(charset)
  • [x] interface Closeable
  • [x] ObjectPool<T>.use(block):R
  • [ ] readUntil for primitive types and ByteArray
  • [ ] readLine with CharsetDecoder
  • [x] readLine until delimiter
  • [x] Input.skip(count) (Input.discard)
  • [x] ByteReadChannel.skip(count)
  • [ ] ByteReadPacket(ByteArray)
  • [ ] Input.lines(): Sequence<String> | List<String>
  • [ ] revert ByteReadChannel.totalBytesRead
  • [ ] Input.copyTo(Output) + joinTo
  • [ ] ByteWriteChannel.writeFully(Input)

Jvm integration

  • [ ] Input.asStream(): InputStream
  • [x] InputStream.asInput(): Input

Charset shortcuts:

  • [x] ISO_8859_1

Input/Output

  • [ ] BE and LE API for reading and writing(including primitive types)

e5l avatar Jun 26 '18 13:06 e5l

Wishlist from my side (maybe all, or some of them are already included):

ByteArray -> ByteReadChannel (with optional range) String -> ByteReadChannel providing a Charset ByteReadChannel -> read to ByteArray (the last time I tried I think it required to read a packet first) maybe an argument to specify max length to limit memory usage throwing an exception if it is bigger ByteReadChannel -> read to String providing a Charset ByteArray.toString(charset) String.toByteArray(charset)


java.nio.channels.AsynchronousByteChannel bidirectional conversion with ReadByteChannel and WriteByteChannel


Would be nice to provide them as extension functions to allow easily writing and discovery.

soywiz avatar Jun 26 '18 15:06 soywiz

ByteReadChannel.readText(charset: Charset = Charsets.UTF_8): String

sandwwraith avatar Aug 06 '18 14:08 sandwwraith

AsynchronousFileChannel -> ReadByteChannel and WriteByteChannel would also be nice

clarfonthey avatar Aug 24 '18 13:08 clarfonthey

Not sure if this is the right issue to request this, but would it make sense to move the goodies from https://github.com/ktorio/ktor/blob/7da470df9c5f067605503badf1a0d31ab9272c56/ktor-utils/ktor-utils-jvm/src/io/ktor/util/cio/FileChannels.kt into kotlinx-io?

ksimons avatar Oct 14 '18 20:10 ksimons

We're rebooting the kotlinx-io development (see https://github.com/Kotlin/kotlinx-io/issues/131), all issues related to the previous versions will be closed. Consider reopening it if the issue remains (or the feature is still missing) in a new version.

fzhinkin avatar Jun 12 '23 11:06 fzhinkin