<!--
{
  "availability" : [
    "iOS: 13.4.0 -",
    "iPadOS: 13.4.0 -",
    "macCatalyst: 13.4.0 -",
    "macOS: 10.15.4 -",
    "tvOS: 13.4.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.2.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileHandle/readToEnd()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:So12NSFileHandleC10FoundationE9readToEndAC4DataVSgyKF"
  },
  "title" : "readToEnd()"
}
-->

# readToEnd()

Reads the available data synchronously up to the end of file or maximum number of bytes.

```
func readToEnd() throws -> Data?
```

## Return Value

The data available through the file handle up to the maximum size that can be represented by an [`NSData`](/documentation/Foundation/NSData) object or, if a communications channel, until an end-of-file indicator is returned.

## Discussion

This method invokes [`readData(ofLength:)`](/documentation/Foundation/FileHandle/readData(ofLength:)) as part of its implementation.

---

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)