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

# read(_:maxLength:)

Reads up to a given number of bytes into a given buffer.

## Declaration

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

## Parameters

- `buffer`: A data buffer. The buffer must be large enough to contain the number of bytes specified by len.
- `len`: The maximum number of bytes to read.

## Return Value

Return Value A number indicating the outcome of the operation:

## Discussion

Discussion A positive number indicates the number of bytes read. 0 indicates that the end of the buffer was reached. -1 means that the operation failed; more information about the error can be obtained with streamError.

## See Also

### Using Streams

- [getBuffer(_:length:)](foundation/inputstream/getbuffer(_:length:).md)
- [hasBytesAvailable](foundation/inputstream/hasbytesavailable.md)
