Offer-derived parameters; see ReceiveTransferParams. The transfer starts in TransferState.Offered, awaiting ReceiveTransfer.accept.
Protected_Current lifecycle state.
Protected_Bytes transferred so far.
Protected_Chunks transferred so far.
Protected ReadonlychunkPayload bytes per chunk.
ReadonlydirectionAlways TransferDirection.Receive.
ReadonlyidUnique identifier shared by both peers for this transfer.
ReadonlymetadataName, MIME type, and size of the file being transferred.
ReadonlypeerIdentifier of the remote peer participating in this transfer.
Protected ReadonlytotalTotal number of chunks the file is divided into.
Convenience accessor for the offered file name (equivalent to metadata.name).
true once the transfer has reached a terminal state (completed, failed, or cancelled).
The sink's finalized output (blob, byte array, and/or path), or null until the transfer
reaches TransferState.Completed.
The current lifecycle state of the transfer.
Protected_Hook invoked by Transfer.fail when a local failure must be signalled to the remote peer. Overridden by the concrete subclasses to send a cancel over the control channel; a no-op by default.
Protected_Hook invoked once when the transfer first reaches a terminal state (completed/failed/cancelled). Subclasses override it to release resources — close per-transfer data channels, drain any suspended workers, clear timers.
Accepts the offer and begins receiving into sink.
Opens the sink, transitions the transfer to active, and sends an accept control message (including any chunks already buffered, to support resume). If the transfer is not in TransferState.Offered, or the sink fails to open, the transfer fails instead.
Destination the received bytes are written to (for example MemorySink).
Binds an inbound binary data channel to this transfer and starts consuming framed chunks from it. Called by FileTransferManager as the sender's parallel channels open; may be invoked multiple times (once per parallel channel).
The data channel carrying framed chunk payloads for this transfer.
Cancels the transfer, notifying the sender and aborting the sink. No-op if already terminal.
Optionalreason: stringOptional reason; when provided, surfaced via TransferEvent.Error.
Synchronously invokes every listener registered for event, in registration order.
The event name to emit.
The argument tuple to pass to each listener, matching Events[event].
true if at least one listener was invoked, false if there were none.
The listener list is snapshotted before dispatch, so mutations made by handlers take effect only on subsequent emissions. Listeners are isolated: if one throws, the remaining listeners still run and the error is surfaced via console.error rather than swallowed silently (consistent with LocalMessageBus).
ProtectedemitEmits a TransferEvent.Progress event with the current snapshot.
ProtectedfailTransitions the transfer to TransferState.Failed and emits TransferEvent.Error. No-op if the transfer is already terminal.
The error describing the failure.
The same error, for convenient throw/return chaining.
Processes an inbound control message from the sender. A sent message records the
sender-computed digest and marks the stream complete (triggering finalization once all
chunks have arrived); a cancel aborts the transfer. Routed here by FileTransferManager.
The decoded control message.
Optionalversion?: numberProtocol version of the sender; see FT_PROTOCOL_VERSION. Optional for back-compat.
Returns the number of listeners currently registered for event.
The event name to count listeners for.
The count of registered listeners (0 if none).
Removes a previously registered listener for event.
The event name the listener was registered for.
This emitter, for chaining.
Registers a listener that is invoked every time event is emitted.
The event name to listen for.
Callback invoked with the event's argument tuple.
This emitter, for chaining.
Registers a listener that is invoked at most once: it is removed automatically before
being called the first time event is emitted.
The event name to listen for.
Callback invoked with the event's argument tuple on the next emission.
This emitter, for chaining.
Remove a pending one-time listener by passing the same function reference to off.
Requests that the sender pause streaming and notifies it. No-op unless the transfer is TransferState.Active.
Returns a point-in-time TransferProgress snapshot.
Current byte/chunk counts and completion ratio (ratio is 0 for zero-byte files).
Declines the offer, notifying the sender. No-op unless the transfer is TransferState.Offered.
Optionalreason: stringOptional human-readable reason relayed to the sender.
Removes listeners for a single event, or for all events.
Optionalevent: keyof TransferEventsThe event name to clear; if omitted, listeners for every event are removed.
This emitter, for chaining.
Ask the sender to resume, reporting the chunks already received so only the missing ones are resent. Invoked by FileTransferManager when the sender re-announces an in-progress transfer after a reconnect. No-op if the transfer is terminal or has not yet been accepted.
Requests that the sender resume streaming and notifies it. No-op unless the transfer is TransferState.Paused.
ProtectedtoNormalizes an unknown thrown value into a FileTransferError tagged with this transfer's id, passing through existing FileTransferErrors unchanged.
The caught value.
The FileTransferErrorCode to assign when wrapping.
Optionalmessage: stringOptional override message; otherwise derived from err.
A FileTransferError suitable for Transfer.fail.
ProtectedtransitionAttempts a state transition, enforcing the legal-transition table.
The state to move to.
true if the transition occurred (or was a no-op because already in next);
false if the transfer is already terminal or the transition is illegal. Transitions to
TransferState.Failed and TransferState.Cancelled are always permitted from
any non-terminal state.
A file transfer in the receiving direction.
Created when a remote offer arrives (see FileTransferEvent.IncomingOffer). The application inspects ReceiveTransfer.metadata and then calls ReceiveTransfer.accept with a StorageSink — or ReceiveTransfer.reject to decline. Once accepted, framed chunks arriving on the data channel(s) are decoded, deduplicated, hashed (when checksums are enabled), and written to the sink at their byte offset. When the sender signals it is done and every chunk has been received, the digest is verified, the sink is closed, and the resulting SinkResult is exposed via ReceiveTransfer.result.
Example