---
title: "preallocateSpace(for:at:length:flags:replyHandler:)"
framework: fskit
role: symbol
role_heading: Instance Method
path: "fskit/fsvolume/preallocateoperations/preallocatespace(for:at:length:flags:replyhandler:)"
---

# preallocateSpace(for:at:length:flags:replyHandler:)

Preallocates disk space for the given item.

## Declaration

```swift
func preallocateSpace(for item: FSItem, at offset: off_t, length: Int, flags: FSVolume.PreallocateFlags, replyHandler reply: @escaping @Sendable (Int, (any Error)?) -> Void)
```

```swift
func preallocateSpace(for item: FSItem, at offset: off_t, length: Int, flags: FSVolume.PreallocateFlags) async throws -> Int
```

## Parameters

- `item`: The item for which to preallocate space.
- `offset`: The offset from which to allocate.
- `length`: The length of the space in bytes.
- `flags`: Flags that affect the preallocation behavior.
- `reply`: A block or closure to indicate success or failure. If preallocation succeeds, pass the amount of bytes allocated and a nil error. If preallocation fails, pass the relevant error as the second parameter; FSKit ignores any byte count in this case. For an async Swift implementation, there’s no reply handler; simply return the allocated byte count or throw an error.
