<!--
{
  "availability" : [
    "macOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "DiskImageKit",
  "identifier" : "/documentation/DiskImageKit/DiskImage/truncate(blockCount:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "DiskImageKit"
    ],
    "preciseIdentifier" : "s:12DiskImageKit0aB0C8truncate10blockCountySi_tKF"
  },
  "title" : "truncate(blockCount:)"
}
-->

# truncate(blockCount:)

Truncate or extend the disk image to a new size.

```
func truncate(blockCount: Int) throws
```

## Parameters

`blockCount`

The new size in blocks for the disk image. `blockCount` must be greater than zero.

## Discussion

This changes the size of the disk image itself, but not its contents, such as file systems, partition map, and so on.
Shrinking the disk image may cause data loss if the file system inside it exceeds the new size.
The image must not be a cache image.
For a stacked disk image, the top layer is truncated, as the stack size equals to its top layer’s size.

> Throws: ``doc://com.apple.diskimagekit/documentation/DiskImageKit/InvalidBlockCountError`` if the block count is zero or negative.
> `POSIXError` if the truncate operation fails.

---

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)