<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFWriteStreamWrite(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@F@CFWriteStreamWrite"
  },
  "title" : "CFWriteStreamWrite(_:_:_:)"
}
-->

# CFWriteStreamWrite(_:_:_:)

Writes data to a writable stream.

```
func CFWriteStreamWrite(_ stream: CFWriteStream!, _ buffer: UnsafePointer<UInt8>!, _ bufferLength: CFIndex) -> CFIndex
```

## Parameters

`stream`

The stream to which to write.

`buffer`

The buffer holding the data to write.

`bufferLength`

The number of bytes from `buffer` to write.

## Return Value

The number of bytes successfully written, `0` if the stream has been filled to capacity (for fixed-length streams), or `-1` if either the stream is not open or an error occurs.

## Discussion

If `stream` is in the process of opening, this function waits until it has completed. If the stream is not full, this call blocks until at least one byte is written; it does not block until all the bytes in `buffer` is written. To avoid blocking, call this function only if [`CFWriteStreamCanAcceptBytes(_:)`](/documentation/CoreFoundation/CFWriteStreamCanAcceptBytes(_:)) returns `true` or after the stream’s client (set with [`CFWriteStreamSetClient(_:_:_:_:)`](/documentation/CoreFoundation/CFWriteStreamSetClient(_:_:_:_:))) is notified of a [`canAcceptBytes`](/documentation/CoreFoundation/CFStreamEventType/canAcceptBytes) event.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)