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

Easy way to implement limit?

Open octylFractal opened this issue 6 years ago • 3 comments

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.

octylFractal avatar Feb 06 '19 20:02 octylFractal

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.

altavir avatar Nov 25 '19 10:11 altavir

In new IO it's relatively easy to implement limit, though it won't be zero-copy (neither it can be by design)

qwwdfsad avatar Nov 25 '19 11:11 qwwdfsad

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.

altavir avatar Nov 25 '19 13:11 altavir

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