---
title: "write(_:maxLength:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/outputstream/write(_:maxlength:)"
---

# write(_:maxLength:)

Writes the contents of a provided data buffer to the receiver.

## Declaration

```swift
func write(_ buffer: UnsafePointer<UInt8>, maxLength len: Int) -> Int
```

## Parameters

- `buffer`: The data to write.
- `len`: The length of the data buffer, in bytes. important: The behavior of this method is undefined if you pass a negative or zero number.

## Mentioned in

Uploading streams of data

## Return Value

Return Value A number indicating the outcome of the operation: A positive number indicates the number of bytes written. 0 indicates that a fixed-length stream and has reached its capacity. -1 means that the operation failed; more information about the error can be obtained with streamError.

## See Also

### Using Streams

- [hasSpaceAvailable](foundation/outputstream/hasspaceavailable.md)
