<!--
{
  "availability" : [
    "iOS: 17.4.0 -",
    "iPadOS: 17.4.0 -",
    "macCatalyst: 17.4.0 -",
    "macOS: 14.4.0 -",
    "tvOS: 17.4.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "System",
  "identifier" : "/documentation/System/FileDescriptor/resize(to:retryOnInterrupt:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "System"
    ],
    "preciseIdentifier" : "s:6System14FileDescriptorV6resize2to16retryOnInterruptys5Int64V_SbtKF"
  },
  "title" : "resize(to:retryOnInterrupt:)"
}
-->

# resize(to:retryOnInterrupt:)

Truncates or extends the file referenced by this file descriptor.

```
func resize(to newSize: Int64, retryOnInterrupt: Bool = true) throws
```

## Parameters

`newSize`

The length in bytes to resize the file to.

`retryOnInterrupt`

Whether to retry the write operation
if it throws [`interrupted`](/documentation/System/Errno/interrupted). The default is `true`.
Pass `false` to try only once and throw an error upon interruption.

## Discussion

The file referenced by this file descriptor will by truncated (or extended) to `newSize`.

If the current size of the file exceeds `newSize`, any extra data is discarded. If the current
size of the file is smaller than `newSize`, the file is extended and filled with zeros to the
provided size.

This function requires that the file has been opened for writing.

> Note: This function does not modify the current offset for any open file descriptors
> associated with the file.

The corresponding C function is `ftruncate`.

---

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)