/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { OutboundFlow } from "./OutboundFlow.js";
class DrivenSendingFlow extends OutboundFlow {
  async transferNextChunk() {
    const { asynchronousTransfer } = this.transferParameters;
    const { iterator } = this.stream;
    const blockCounter = this.nextMessageCounter;
    const { data, done } = await this.readDataChunk(iterator);
    if (done) {
      await this.messenger.sendBlockEof({ data: data ?? new Uint8Array(), blockCounter });
      this.transferredBytes += data?.byteLength ?? 0;
      this.finalBlockCounter = blockCounter;
      return true;
    }
    await this.messenger.sendBlock({ data, blockCounter });
    this.transferredBytes += data.byteLength;
    if (!asynchronousTransfer) {
      const { blockCounter: ackedBlockCounter } = await this.messenger.readBlockAck();
      this.validateCounter(ackedBlockCounter, blockCounter);
    }
    return false;
  }
}
export {
  DrivenSendingFlow
};
//# sourceMappingURL=DrivenSendingFlow.js.map
