---
title: "truncate(blockCount:)"
framework: diskimagekit
role: symbol
role_heading: Instance Method
path: "diskimagekit/diskimage/truncate(blockcount:)"
---

# truncate(blockCount:)

Truncate or extend the disk image to a new size.

## Declaration

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

## Parameters

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

## Discussion

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. note: InvalidBlockCountError if the block count is zero or negative. POSIXError if the truncate operation fails.
