After sending a flow controlled frame, the sender reduces the space available in both windows by
the length of the transmitted frame. For flow control calculations, the 8 byte frame header is
not counted.
Stream.prototype._write = function _write(buffer, encoding, done) {
var chunks = utils.cut(buffer, MAX_HTTP_PAYLOAD_SIZE);
var sent = 0;
while (chunks.length > 0 && chunks[0].length <= this.window) {
var chunk = chunks.shift();
sent += chunk.length;
this.window -= chunk.length;
this._send({
type: 'DATA',
flags: {},
data: chunk
});
}
if (chunks.length === 0) {
done();
} else {
this.once('window_update', this._write.bind(this, buffer.slice(sent), encoding, done));
}
};