<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Tor",
  "identifier" : "/documentation/Tor/ControlSocket/writeData(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Tor"
    ],
    "preciseIdentifier" : "s:3Tor13ControlSocketC9writeDatayy10Foundation0E0VKF"
  },
  "title" : "writeData(_:)"
}
-->

# writeData(_:)

Send a raw byte payload, looping until every byte is written.

```
func writeData(_ data: Data) throws
```

## Parameters

`data`

The bytes to write verbatim.

## Discussion

Low-level counterpart to [`writeLine(_:)`](/documentation/Tor/ControlSocket/writeLine(_:)). Called when the
caller needs to ship a pre-assembled payload (multi-line
commands, binary-safe extensions). Loops over `send(2)` until
the full `data` has been drained, handling short writes
transparently.

> Throws: ``doc://Tor/documentation/Tor/TorError/ioError(_:)`` if the FD is closed or any
> `send(2)` returns `-1`.

> Important: Partial writes are **not** reported to the caller —
> swift-tor retries transparently. If `send(2)` fails mid-
> payload the caller must treat the socket as compromised and
> abandon it; the Tor peer has consumed an unknown prefix of
> the intended command.