---
title: readDataToEndOfFile()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/filehandle/readdatatoendoffile()
---

# readDataToEndOfFile()

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

## Declaration

```swift
func readDataToEndOfFile() -> Data
```

## Return Value

Return Value The data available through the receiver up to 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. important: This method raises fileHandleOperationException if attempts to determine the file-handle type fail or if attempts to read from the file or channel fail.

## See Also

### Related Documentation

- [availableData](foundation/filehandle/availabledata.md)

### Deprecated

- [readData(ofLength:)](foundation/filehandle/readdata(oflength:).md)
- [write(_:)](foundation/filehandle/write(_:).md)
- [offsetInFile](foundation/filehandle/offsetinfile.md)
- [seekToEndOfFile()](foundation/filehandle/seektoendoffile().md)
- [seek(toFileOffset:)](foundation/filehandle/seek(tofileoffset:).md)
- [closeFile()](foundation/filehandle/closefile().md)
- [synchronizeFile()](foundation/filehandle/synchronizefile().md)
- [truncateFile(atOffset:)](foundation/filehandle/truncatefile(atoffset:).md)
- [NSFileHandleNotificationMonitorModes](foundation/nsfilehandlenotificationmonitormodes.md)
