We're migrating to the new kotlinx-io library.
This declaration is deprecated and will be removed in Ktor 4.0.0
If you have any problems with migration, please contact us in
Channel for asynchronous reading and writing of sequences of bytes. This is a buffered single-reader single-writer channel.
Read operations can be invoked concurrently with write operations, but multiple reads or multiple writes cannot be invoked concurrently with themselves. Exceptions are close and flush which can be invoked concurrently with any other operations and between themselves at any time.
Close channel with optional cause cancellation. Unlike ByteWriteChannel.close that could close channel normally, cancel does always close with error so any operations on this channel will always fail and all suspensions will be resumed with exception.
Closes this channel with an optional exceptional cause. It flushes all pending write bytes (via flush). This is an idempotent operation -- repeated invocations of this function have no effect and return false.
Try to copy at least min but up to max bytes to the specified destination buffer from this input skipping offset bytes. If there are not enough bytes available to provide min bytes after skipping offset bytes then it will trigger the underlying source reading first and after that will simply copy available bytes even if EOF encountered so min is not a requirement but a desired number of bytes. It is safe to specify max greater than the destination free space. min shouldn't be bigger than the destination free space. This function could trigger the underlying source suspending reading. It is allowed to specify too big offset so in this case this function will always return 0 after prefetching all underlying bytes but note that it may lead to significant memory consumption. This function usually copy more bytes than min (unless max = min) but it is not guaranteed. When 0 is returned with offset = 0 then it makes sense to check isClosedForRead.
Starts a suspendable read session. After channel preparation consumer lambda will be invoked immediately even if there are no bytes available for read yet. consumer lambda could suspend as much as needed.
Reads a line of UTF-8 characters to the specified out buffer up to limit characters. Supports both CR-LF and LF line endings. No line ending characters will be appended to out buffer. Throws an exception if the specified limit has been exceeded.
For every available bytes range invokes visitor function until it return false or end of stream encountered. The provided buffer should be never captured outside of the visitor block otherwise resource leaks, crashes and data corruptions may occur. The visitor block may be invoked multiple times, once or never.
Copy up to limit bytes to blocking NIO channel. Copying to a non-blocking channel requires selection and not supported. It is suspended if no data are available in a byte channel but may block if destination NIO channel blocks.
Await until at least desiredSize is available for read or EOF and invoke block function. The block function should never capture a provided Memory instance outside otherwise an undefined behaviour may occur including accidental crash or data corruption. Block function should return number of bytes consumed or 0.
Await for desiredSpace will be available for write and invoke block function providing Memory instance and the corresponding range suitable for wiring in the memory. The block function should return number of bytes were written, possibly 0.