<!--
{
  "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/InputStream/read(_:maxLength:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSInputStream(im)read:maxLength:"
  },
  "title" : "read(_:maxLength:)"
}
-->

# read(_:maxLength:)

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

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

A number indicating the outcome of the operation:

## 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`](/documentation/Foundation/Stream/streamError).

---

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)