---
title: "init(type:path:oflag:mode:queue:cleanupHandler:)"
framework: dispatch
role: symbol
role_heading: Initializer
path: "dispatch/dispatchio/init(type:path:oflag:mode:queue:cleanuphandler:)-50rb0"
---

# init(type:path:oflag:mode:queue:cleanupHandler:)

Creates a new I/O channel that accesses the file at the specified path, potentially creating that file in the process.

## Declaration

```swift
convenience init?(type: DispatchIO.StreamType, path: UnsafePointer<Int8>, oflag: Int32, mode: mode_t, queue: DispatchQueue, cleanupHandler: @escaping (Int32) -> Void)
```

## Parameters

- `type`: The access semantics for the channel. For a list of possible values, see doc://com.apple.dispatch/documentation/Dispatch/DispatchIO/StreamType.
- `path`: The absolute path of the file you want to open.
- `oflag`: The flags to pass to open(2) when opening the file at the specified path.
- `mode`: The mode flags to pass to open(2). Specify O_CREAT to create the file at the specified path; otherwise, specify 0.
- `queue`: The dispatch queue on which to perform work.
- `cleanupHandler`: The handler to execute once the channel is closed. This block has no return value and takes the following parameter:

## Discussion

Discussion This method opens the channel by passing the path, oflag, and mode parameters to the low-level open(2) function. The file descriptor returned by that function remains open and under system control until you close the channel, or until an error occurs that causes the channel to release the file descriptor. After closing the file descriptor, the channel executes the specified cleanupHandler block on queue.

## See Also

### Creating a Dispatch I/O Object

- [init(type:fileDescriptor:queue:cleanupHandler:)](dispatch/dispatchio/init(type:filedescriptor:queue:cleanuphandler:).md)
- [init(type:io:queue:cleanupHandler:)](dispatch/dispatchio/init(type:io:queue:cleanuphandler:).md)
- [DispatchIO.StreamType](dispatch/dispatchio/streamtype.md)
