kotlinx-io
kotlinx-io copied to clipboard
Easy way to implement limit?
I want to be able to limit
an Input
, but it doesn't seem like the functionality exists. I attempted to implement it with a new AbstractInput
subclass, but I couldn't understand how head
and remaining
are supposed to function. I want to know if it would be possible to add this functionality to Input
as an extension function, or -- if this is actual trivial to implement on my end -- some direction on how AbstractInput
functions.
I found that I need this feature as well in io-2. Current design gives fairly good idea how to use copy part of Input
into new Input
, but it seems not possible to make a zero-copy view of Input
.
In new IO it's relatively easy to implement limit
, though it won't be zero-copy (neither it can be by design)
It is quite easy to do with copy. I have a working example with input to output copy. But the idea is that you seldom need to limit how many bytes could be read and report preliminary EOF, and making complete input copy for that is an overkill. It is not hard to add manual limitation to the Input class, but I am not sure it is strictly necessary. For now workarounds seems rather elegant. I will write again if I hit real problem with this.
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.