<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/OutputStream/init(toBuffer:capacity:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSOutputStream(im)initToBuffer:capacity:"
  },
  "title" : "init(toBuffer:capacity:)"
}
-->

# init(toBuffer:capacity:)

Returns an initialized output stream that can write to a provided buffer.

```
init(toBuffer buffer: UnsafeMutablePointer<UInt8>, capacity: Int)
```

## Parameters

`buffer`

The buffer the output stream will write to.

`capacity`

The size of the buffer in bytes.

## Return Value

An initialized output stream that can write to `buffer`.

## Discussion

The stream must be opened before it can be used.

When the number of bytes written to `buffer` has reached `capacity`, the stream’s [`streamStatus`](/documentation/Foundation/Stream/streamStatus) will return `NSStreamStatusAtEnd`.

## See Also

[`outputStreamToBuffer:capacity:`](/documentation/Foundation/NSOutputStream/outputStreamToBuffer:capacity:)

Creates and returns an initialized output stream that can write to a provided buffer.



---

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)