FileHandleProtocol
A handle for a file system object.
- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
protocol FileHandleProtocol
Browse conforming typesThere is a hierarchy of file handle protocols which allow for different functionality. All file handle protocols refine the base FileHandleProtocol
protocol.
┌────────────────────┐
│ FileHandleProtocol │
│ [Protocol] │
└────────────────────┘
▲
┌──────────────────────────────┼────────────────────────────────┐
│ │ │
┌────────────────────────────┐ ┌────────────────────────────┐ ┌─────────────────────────────┐
│ ReadableFileHandleProtocol │ │ WritableFileHandleProtocol │ │ DirectoryFileHandleProtocol │
│ [Protocol] │ │ [Protocol] │ │ [Protocol] │
└────────────────────────────┘ └────────────────────────────┘ └─────────────────────────────┘
File Information
func info(
) async throws -> FileInfo Returns information about the file.
Permissions
func replacePermissions(FilePermissions
) async throws Replaces the permissions set on the file.
func addPermissions(FilePermissions
) async throws -> FilePermissions Adds permissions to the existing permissions set for the file.
func removePermissions(FilePermissions
) async throws -> FilePermissions Remove permissions from the existing permissions set for the file.
Extended Attributes
func attributeNames(
) async throws -> [String] Returns an array containing the names of all extended attributes set on the file.
func valueForAttribute(String
) async throws -> [UInt8] Returns the value for the named attribute if it exists;
nil
otherwise.func updateValueForAttribute(some (Sendable & RandomAccessCollection<UInt8>), attribute: String
) async throws Replaces the value for the named attribute, creating it if it didn’t already exist.
func removeValueForAttribute(String
) async throws Removes the value for the named attribute if it exists.
Descriptor Management
func synchronize(
) async throws Synchronize modified data and metadata to a permanent storage device.
func withUnsafeDescriptor<R>(@escaping (FileDescriptor) throws -> R
) async throws -> R Runs the provided callback with the file descriptor for this handle.
func detachUnsafeFileDescriptor(
) throws -> FileDescriptor Detaches and returns the file descriptor from the handle.
func close(
) async throws Closes the file handle.