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

# write(from:startingAt:length:)

Synchronously writes data from from a buffer to the resource and executes a block afterwards.

```
func write(from buffer: UnsafeRawBufferPointer, startingAt offset: off_t, length: Int) throws -> Int
```

## 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.

## Return Value

The actual number of bytes written.

## Discussion

This method is a synchronous version of [`writeFrom:startingAt:length:completionHandler:`](/documentation/FSKit/FSBlockDeviceResource/writeFrom:startingAt:length:completionHandler:).

In some cases, this method performs a partial write. In this case, the return value is shorter than the requested length, and the `error` is set to `nil`.

> Throws: Any error encountered while writing data.

---

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)