---
title: "read(from:at:length:into:replyHandler:)"
framework: fskit
role: symbol
role_heading: Instance Method
path: "fskit/fsvolume/readwritehandler/read(from:at:length:into:replyhandler:)"
---

# read(from:at:length:into:replyHandler:)

Reads the contents of the given file item.

## Declaration

```swift
func read(from item: FSItem, at offset: off_t, length: Int, into buffer: FSMutableFileDataBuffer, replyHandler reply: @escaping @Sendable (FSReadFileResult?, (any Error)?) -> Void)
```

```swift
func read(from item: FSItem, at offset: off_t, length: Int, into buffer: FSMutableFileDataBuffer) async throws -> FSReadFileResult
```

## Parameters

- `item`: The item from which to read. FSKit guarantees this item will be of type doc://FSKit/documentation/FSKit/FSItem/ItemType/file.
- `offset`: The offset in the file from which to start reading.
- `length`: The number of bytes to read.
- `buffer`: A buffer to receive the bytes read from the file.
- `reply`: A block or closure to indicate success or failure. If reading succeeds, pass an instance of doc://FSKit/documentation/FSKit/FSReadFileResult containing the number of bytes read and the updated doc://FSKit/documentation/FSKit/FSItem/Attributes of the file, along with a nil error. If reading fails, pass the relevant error as the second parameter; FSKit ignores the doc://FSKit/documentation/FSKit/FSReadFileResult instance in this case. For an async Swift implementation, there’s no reply handler; simply return the result instance or throw an error.

## Discussion

Discussion If the number of bytes requested exceeds the number of bytes available before the end of the file, then the call copies only those bytes to buffer. If offset points past the last valid byte of the file, don’t reply with an error but set actuallyRead to 0.

## See Also

### Reading and writing

- [FSMutableFileDataBuffer](fskit/fsmutablefiledatabuffer.md)
- [FSReadFileResult](fskit/fsreadfileresult.md)
- [write(contents:to:at:replyHandler:)](fskit/fsvolume/readwritehandler/write(contents:to:at:replyhandler:).md)
- [FSWriteFileResult](fskit/fswritefileresult.md)
