Best-effort
Flushes any buffered partial block, waits for every outstanding block to
be acknowledged, and sends
Hands the bytes over: a sub-block remainder stays buffered by reference until a later write or close() sends it, so the caller must not mutate the array after this resolves (the same contract as a WHATWG or Node stream sink — reusing a scratch buffer between writes corrupts the tail).
Resolves once every full block it produced has been sent, not acked:
with a window > 1 those blocks are still outstanding. It still blocks
while the window is full, so it remains the backpressure the callers'
pump loops rely on — it just yields after window blocks instead of
one. A block that fails later is reported by a subsequent write() or by
close(), which waits for every outstanding ack.
XEP-0047 In-Band Bytestreams, both directions.
Sending uses IQ-carried exclusively: each block is acknowledged by an IQ result, which provides flow control and error propagation for free. Up to
windowblocks are in flight at once — the result of block k is what releases block k+window — so throughput stops being one block per round trip without giving up the acks. Receiving additionally tolerates message-carried for interop.Ordering is preserved by construction and nowhere else: a block is taken from the buffer, base64-encoded, given its seq and handed to iqCaller in one synchronous step, and both @xmpp/connection and the mock session reach their socket write synchronously from request(). The receiver accepts no gaps (a seq jump kills the stream), so an await anywhere between taking a block and sending it would corrupt the stream rather than merely slow it.
Unsolicited incomings are not accepted: only sids pre-announced via
expectIncoming() are. Because the announcing stanza and the can race
in the event loop, an unclaimed is parked briefly (the IQ reply is
simply withheld) before being refused with .