From: "ioquatix (Samuel Williams)" Date: 2022-10-15T00:52:44+00:00 Subject: [ruby-core:110298] [Ruby master Feature#15560] Add support for read/write offsets. Issue #15560 has been updated by ioquatix (Samuel Williams). Status changed from Open to Closed Assignee set to ioquatix (Samuel Williams) I tried making a PR, but I think we should give up. `IO#read(length, buffer, offset)` can work okay. But doing the same for `write` is very hard because the interface is more general - it tries to write all arguments. It would need to be a keyword argument, and I'm not sure how you'd make it work since you can specify multiple arguments. I think the solution here, for more complex use cases, is just to use `IO::Buffer` which supports this very naturally. ---------------------------------------- Feature #15560: Add support for read/write offsets. https://bugs.ruby-lang.org/issues/15560#change-99584 * Author: ioquatix (Samuel Williams) * Status: Closed * Priority: Normal * Assignee: ioquatix (Samuel Williams) ---------------------------------------- It would be nice if read/write/send/recv/etc methods could accept an offset argument. e.g. ``` socket = Socket.new(...) buffer = String.b socket.read(1024, buffer) socket.read(1024, buffer, offset: buffer.bytesize) ``` The same for write, e.g. ``` socket = Socket.new(...) buffer = String.b amount = socket.write(buffer) socket.write(buffer, offset: amount) ``` Could also include "size:" so that we can selectively write parts of the buffer. -- https://bugs.ruby-lang.org/ Unsubscribe: