kotlinx-io
kotlinx-io copied to clipboard
Add some useful extensions
Let's consider to add some useful extensions:
- [x]
fun String.toByteReadChannel(charset) - [x]
interface Closeable - [x]
ObjectPool<T>.use(block):R - [ ]
readUntilfor primitive types andByteArray - [ ]
readLinewithCharsetDecoder - [x]
readLineuntil 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
- [ ]
BEandLEAPI for reading and writing(including primitive types)
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.
ByteReadChannel.readText(charset: Charset = Charsets.UTF_8): String
AsynchronousFileChannel -> ReadByteChannel and WriteByteChannel would also be nice
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?
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.