resize(to:retryOnInterrupt:)
Truncates or extends the file referenced by this file descriptor.
Declaration
func resize(to newSize: Int64, retryOnInterrupt: Bool = true) throwsParameters
- newSize:
The length in bytes to resize the file to.
- retryOnInterrupt:
Whether to retry the write operation if it throws Interrupted. The default is
true. Passfalseto 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.
The corresponding C function is ftruncate.