<!--
{
  "availability" : [
    "iOS: 2.0.0 - 27.0.0",
    "iPadOS: 2.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.0.0 - 27.0.0",
    "tvOS: 9.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0",
    "watchOS: 2.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileHandle/readDataToEndOfFile()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileHandle(im)readDataToEndOfFile"
  },
  "title" : "readDataToEndOfFile()"
}
-->

# readDataToEndOfFile()

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

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

## Return Value

The data available through the receiver up to 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.

> Important:
> This method raises ``doc://com.apple.foundation/documentation/Foundation/NSExceptionName/fileHandleOperationException`` if attempts to determine the file-handle type fail or if attempts to read from the file or channel fail.

## See Also

[`availableData`](/documentation/Foundation/FileHandle/availableData)

The data currently available in the receiver.



---

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)