I need to read parts of a (binary) stream, and concatenate them, so I can read from that concatenated buffer. I’m reconstructing a thing that was packetized into segments.
I see I can do
write(iob, read(s, ...)), but I am afraid that will do two copies and an intermediate allocation. Allocating the result of the
read, copying data once to the result, then copying it again to the IOBuffer. Is there a way to copy directly from the stream to the IOBuffer?
Even better, could the compiler notice and optimize this case so I can write the code above, but the compiler arranges to not materialize the result of the