---
title: readToEnd()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/filehandle/readtoend()
---

# readToEnd()

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

## Declaration

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

## Return Value

Return Value The data available through the file handle up to the maximum size that can be represented by an NSData object or, if a communications channel, until an end-of-file indicator is returned.

## Discussion

Discussion This method invokes readData(ofLength:) as part of its implementation.

## See Also

### Reading from a file handle synchronously

- [availableData](foundation/filehandle/availabledata.md)
- [read(upToCount:)](foundation/filehandle/read(uptocount:).md)
