+ // We have to keep track of from where in the text we begin creating the
+ // buffer for the flush in the next iteration.
+ let textOffset = 0;
+
+ let remaining = length;
+ while (remaining > 0) {
+
+ const flushSize = Math.min(remaining, (sock._sQbufferSize - sock._sQlen));
+ if (flushSize <= 0) {
+ this._fail("Clipboard contents could not be sent");
+ break;
+ }
+
+ for (let i = 0; i < flushSize; i++) {
+ buff[sock._sQlen + i] = text.charCodeAt(textOffset + i);
+ }
+
+ sock._sQlen += flushSize;
+ sock.flush();
+
+ remaining -= flushSize;
+ textOffset += flushSize;
+ }