<!--
{
  "availability" : [
    "macOS: 15.4.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "FSKit",
  "identifier" : "/documentation/FSKit/FSVolume/ReadWriteOperations/write(contents:to:at:replyHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "FSKit"
    ],
    "preciseIdentifier" : "c:objc(pl)FSVolumeReadWriteOperations(im)writeContents:toFile:atOffset:replyHandler:"
  },
  "title" : "write(contents:to:at:replyHandler:)"
}
-->

# write(contents:to:at:replyHandler:)

Writes contents to the given file item.

```
func write(contents: Data, to item: FSItem, at offset: off_t, replyHandler reply: @escaping @Sendable (Int, (any Error)?) -> Void)
```

## Parameters

`contents`

A buffer containing the data to write to the file.

`item`

The item to which to write. FSKit guarantees this item will be of type [`FSItem.ItemType.file`](/documentation/FSKit/FSItem/ItemType/file).

`offset`

The offset in the file from which to start writing.

`reply`

A block or closure to indicate success or failure. If writing succeeds, pass the number of bytes written and a `nil` error. If writing fails, pass the number of bytes written prior to the error along with the relevant error. For an `async` Swift implementation, there’s no reply handler; simply return the byte count or throw an error.

## Discussion

FSKit expects this routine to allocate space in the file system to extend the file as necessary.

If the volume experiences an out-of-space condition, reply with an error of domain <doc://com.apple.documentation/documentation/Foundation/NSPOSIXErrorDomain> and code `ENOSPC`.

---

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)