---
title: "truncate(atOffset:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/filehandle/truncate(atoffset:)"
---

# truncate(atOffset:)

Truncates or extends the file represented by the file handle to a specified offset within the file and puts the file pointer at that position.

## Declaration

```swift
func truncate(atOffset offset: UInt64) throws
```

## Parameters

- `offset`: The offset within the file that marks the new end of the file.

## Discussion

Discussion If the file is extended (if offset is beyond the current end of file), the added characters are null bytes.

## See Also

### Operating on a file

- [close()](foundation/filehandle/close().md)
- [synchronize()](foundation/filehandle/synchronize().md)
