<!--
{
  "availability" : [
    "macOS: 15.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FSKit",
  "identifier" : "/documentation/FSKit/FSBlockDeviceResource/write(from:startingAt:length:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "FSKit"
    ],
    "preciseIdentifier" : "s:So21FSBlockDeviceResourceC5FSKitE5write4from10startingAt6length17completionHandlerySW_s5Int64VSiySi_s5Error_pSgtctF"
  },
  "title" : "write(from:startingAt:length:completionHandler:)"
}
-->

# write(from:startingAt:length:completionHandler:)

Writes data from from a buffer to the resource and executes a closure afterwards.

```
func write(from buffer: UnsafeRawBufferPointer, startingAt offset: off_t, length: Int, completionHandler: @escaping (Int, (any Error)?) -> Void)
```

## Parameters

`buffer`

A buffer to provide the data.

`offset`

The offset into the resource from which to start writing.

`length`

A maximum number of bytes to write. The completion handler receives a parameter with the actual number of bytes write.

`completionHandler`

A closure that executes after the write operation completes. If successful, the first parameter contains the number of bytes actually written. In the case of an error, the second parameter contains a non-`nil` error. This value is `EFAULT` if `buffer` is `NULL`, or `errno` if writing to the resource failed.

## Discussion

For the read to succeed, requests must conform to any transfer requirements of the underlying resource.
Disk drives typically require sector (`physicalBlockSize`) addressed operations of one or more sector-aligned offsets.

---

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)