---
title: "init(toBuffer:capacity:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/outputstream/init(tobuffer:capacity:)"
---

# init(toBuffer:capacity:)

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

## Declaration

```swift
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

Return Value An initialized output stream that can write to buffer.

## Discussion

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 will return NSStreamStatusAtEnd.

## See Also

### Creating Streams

- [toMemory()](foundation/outputstream/tomemory().md)
- [init(toMemory:)](foundation/outputstream/init(tomemory:).md)
- [init(toFileAtPath:append:)](foundation/outputstream/init(tofileatpath:append:).md)
- [init(url:append:)](foundation/outputstream/init(url:append:)-5soau.md)
