@@ -135,11 +135,12 @@ extension _BodyDataSource : _BodySource {
135
135
/// have to be thread safe.
136
136
internal final class _BodyFileSource {
137
137
fileprivate let fileURL : URL
138
- fileprivate let channel : DispatchIO
139
- fileprivate let workQueue : DispatchQueue
138
+ fileprivate let channel : DispatchIO
139
+ fileprivate let workQueue : DispatchQueue
140
140
fileprivate let dataAvailableHandler : ( ) -> Void
141
141
fileprivate var hasActiveReadHandler = false
142
142
fileprivate var availableChunk : _Chunk = . empty
143
+
143
144
/// Create a new data source backed by a file.
144
145
///
145
146
/// - Parameter fileURL: the file to read from
@@ -156,13 +157,13 @@ internal final class _BodyFileSource {
156
157
self . fileURL = fileURL
157
158
self . workQueue = workQueue
158
159
self . dataAvailableHandler = dataAvailableHandler
159
- var fileSystemRepresentation : UnsafePointer < Int8 > ! = nil
160
- fileURL. withUnsafeFileSystemRepresentation {
161
- fileSystemRepresentation = $0
162
- }
163
- guard let channel = DispatchIO ( type : . stream , path : fileSystemRepresentation ,
164
- oflag : O_RDONLY , mode : 0 , queue : workQueue ,
165
- cleanupHandler : { _ in } ) else {
160
+
161
+ guard let channel = fileURL. withUnsafeFileSystemRepresentation ( {
162
+ // DisptachIO (dispatch_io_create_with_path) makes a copy of the path
163
+ DispatchIO ( type : . stream , path : $0! ,
164
+ oflag : O_RDONLY , mode : 0 , queue : workQueue ,
165
+ cleanupHandler : { _ in } )
166
+ } ) else {
166
167
fatalError ( " Cant create DispatchIO channel " )
167
168
}
168
169
self . channel = channel
0 commit comments