Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some useful extensions #4

Closed
8 of 17 tasks
e5l opened this issue Jun 26, 2018 · 5 comments
Closed
8 of 17 tasks

Add some useful extensions #4

e5l opened this issue Jun 26, 2018 · 5 comments

Comments

@e5l
Copy link
Member

e5l commented Jun 26, 2018

Let's consider to add some useful extensions:

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

Jvm integration

  • Input.asStream(): InputStream
  • InputStream.asInput(): Input

Charset shortcuts:

  • ISO_8859_1

Input/Output

  • BE and LE API for reading and writing(including primitive types)
@soywiz
Copy link

soywiz commented Jun 26, 2018

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.

@e5l e5l changed the title Add some useful extensions Add some useful extensions and interfaces Jul 4, 2018
@e5l e5l changed the title Add some useful extensions and interfaces Add some useful extensions Jul 4, 2018
@sandwwraith
Copy link
Member

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

@clarfonthey
Copy link

AsynchronousFileChannel -> ReadByteChannel and WriteByteChannel would also be nice

@ksimons
Copy link

ksimons commented Oct 14, 2018

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?

@fzhinkin
Copy link
Collaborator

We're rebooting the kotlinx-io development (see #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants