---
title: OutputStream
framework: foundation
role: symbol
role_heading: Class
path: foundation/outputstream
---

# OutputStream

A stream that provides write-only stream functionality.

## Declaration

```swift
class OutputStream
```

## Mentioned in

Uploading streams of data

## Overview

Overview OutputStream is “toll-free bridged” with its Core Foundation counterpart, CFWriteStream. For more information on toll-free bridging, see Toll-Free Bridging. Subclassing Notes NSOutputStream is a concrete subclass of NSStream that lets you write data to a stream. Although NSOutputStream is probably sufficient for most situations requiring this capability, you can create a subclass of NSOutputStream if you want more specialized behavior (for example, you want to record statistics on the data in a stream). Methods to Override To create a subclass of NSOutputStream you may have to implement initializers for the type of stream data supported and suitably reimplement existing initializers. You must also provide complete implementations of the following methods: write(_:maxLength:) From the current write pointer, take up to the number of bytes specified in the maxLength: parameter from the client-supplied buffer (first parameter) and put them onto the stream. The buffer must be of the size specified by the second parameter. To prepare for the next operation, offset the write pointer by the number of bytes written. Return a signed integer based on the outcome of the current operation: If the write operation is successful, return the actual number of bytes put onto the stream. If the stream is of a fixed length and has reached its capacity, return 0. If there was an error writing to the stream, return -1. hasSpaceAvailable Return true if the stream can currently accept more data, false if it cannot. If you want to be semantically compatible with NSOutputStream, return true if a write must be attempted to determine if space is available.

## Topics

### Creating Streams

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

### Using Streams

- [hasSpaceAvailable](foundation/outputstream/hasspaceavailable.md)
- [write(_:maxLength:)](foundation/outputstream/write(_:maxlength:).md)

### Initializers

- [init(URL:append:)](foundation/outputstream/init(url:append:)-4dpt1.md)

### Default Implementations

- [NSOutputStream Implementations](foundation/outputstream/nsoutputstream-implementations.md)

## Relationships

### Inherits From

- [Stream](foundation/stream.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Streams

- [Stream](foundation/stream.md)
- [InputStream](foundation/inputstream.md)
- [StreamDelegate](foundation/streamdelegate.md)
