@@ -22,7 +22,7 @@ class FileAccess: RCTEventEmitter {
22
22
@objc ( appendFile: withData: withEncoding: withResolver: withRejecter: )
23
23
func appendFile( path: String , data: String , encoding: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
24
24
guard let encodedData = encoding == " base64 " ? Data ( base64Encoded: data) : data. data ( using: . utf8) ,
25
- let handle = FileHandle ( forWritingAtPath: path) else {
25
+ let handle = FileHandle ( forWritingAtPath: path. path ( ) ) else {
26
26
reject ( " ERR " , " Failed to append to ' \( path) '. " , nil )
27
27
return
28
28
}
@@ -35,7 +35,7 @@ class FileAccess: RCTEventEmitter {
35
35
36
36
@objc ( concatFiles: withTarget: withResolver: withRejecter: )
37
37
func concatFiles( source: String , target: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
38
- guard let input = InputStream ( fileAtPath: source) , let output = OutputStream ( toFileAtPath: target, append: true ) else {
38
+ guard let input = InputStream ( fileAtPath: source. path ( ) ) , let output = OutputStream ( toFileAtPath: target. path ( ) , append: true ) else {
39
39
reject ( " ERR " , " Failed to concat ' \( source) ' to ' \( target) '. " , nil )
40
40
return
41
41
}
@@ -60,7 +60,7 @@ class FileAccess: RCTEventEmitter {
60
60
@objc ( cp: withTarget: withResolver: withRejecter: )
61
61
func cp( source: String , target: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
62
62
do {
63
- try FileManager . default. copyItem ( atPath: source, toPath: target)
63
+ try FileManager . default. copyItem ( atPath: source. path ( ) , toPath: target. path ( ) )
64
64
resolve ( nil )
65
65
} catch {
66
66
reject ( " ERR " , " Failed to copy ' \( source) ' to ' \( target) '. " , error)
@@ -75,7 +75,7 @@ class FileAccess: RCTEventEmitter {
75
75
}
76
76
77
77
do {
78
- try FileManager . default. copyItem ( atPath: assetPath, toPath: target)
78
+ try FileManager . default. copyItem ( atPath: assetPath, toPath: target. path ( ) )
79
79
resolve ( nil )
80
80
} catch {
81
81
reject ( " ERR " , " Failed to copy ' \( asset) ' to ' \( target) '. " , error)
@@ -103,7 +103,7 @@ class FileAccess: RCTEventEmitter {
103
103
104
104
let targetUrl = URL ( fileURLWithPath: targetFolder, isDirectory: true )
105
105
. appendingPathComponent ( targetName, isDirectory: false )
106
- cp ( source: source, target: targetUrl. path, resolve: resolve, reject: reject)
106
+ cp ( source: source. path ( ) , target: targetUrl. path, resolve: resolve, reject: reject)
107
107
}
108
108
109
109
@objc ( df: withRejecter: )
@@ -124,7 +124,7 @@ class FileAccess: RCTEventEmitter {
124
124
125
125
@objc ( exists: withResolver: withRejecter: )
126
126
func exists( path: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
127
- resolve ( FileManager . default. fileExists ( atPath: path) )
127
+ resolve ( FileManager . default. fileExists ( atPath: path. path ( ) ) )
128
128
}
129
129
130
130
@objc ( fetch: withResource: withConfig: )
@@ -145,7 +145,7 @@ class FileAccess: RCTEventEmitter {
145
145
146
146
@objc ( hash: withAlgorithm: withResolver: withRejecter: )
147
147
func hash( path: String , algorithm: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
148
- guard let data = NSData ( contentsOfFile: path) else {
148
+ guard let data = NSData ( contentsOfFile: path. path ( ) ) else {
149
149
reject ( " ERR " , " Failed to read ' \( path) '. " , nil )
150
150
return
151
151
}
@@ -183,14 +183,14 @@ class FileAccess: RCTEventEmitter {
183
183
184
184
@objc ( isDir: withResolver: withRejecter: )
185
185
func isDir( path: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
186
- let status = checkIfIsDirectory ( path: path)
186
+ let status = checkIfIsDirectory ( path: path. path ( ) )
187
187
resolve ( status. exists && status. isDirectory)
188
188
}
189
189
190
190
@objc ( ls: withResolver: withRejecter: )
191
191
func ls( path: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
192
192
do {
193
- try resolve ( FileManager . default. contentsOfDirectory ( atPath: path) )
193
+ try resolve ( FileManager . default. contentsOfDirectory ( atPath: path. path ( ) ) )
194
194
} catch {
195
195
reject ( " ERR " , " Failed to list ' \( path) '. " , error)
196
196
}
@@ -199,7 +199,7 @@ class FileAccess: RCTEventEmitter {
199
199
@objc ( mkdir: withResolver: withRejecter: )
200
200
func mkdir( path: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
201
201
do {
202
- try FileManager . default. createDirectory ( atPath: path, withIntermediateDirectories: true , attributes: nil )
202
+ try FileManager . default. createDirectory ( atPath: path. path ( ) , withIntermediateDirectories: true , attributes: nil )
203
203
resolve ( nil )
204
204
} catch {
205
205
reject ( " ERR " , " Failed to create directory ' \( path) '. " , error)
@@ -209,8 +209,8 @@ class FileAccess: RCTEventEmitter {
209
209
@objc ( mv: withTarget: withResolver: withRejecter: )
210
210
func mv( source: String , target: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
211
211
do {
212
- try ? FileManager . default. removeItem ( atPath: target)
213
- try FileManager . default. moveItem ( atPath: source, toPath: target)
212
+ try ? FileManager . default. removeItem ( atPath: target. path ( ) )
213
+ try FileManager . default. moveItem ( atPath: source. path ( ) , toPath: target. path ( ) )
214
214
resolve ( nil )
215
215
} catch {
216
216
reject ( " ERR " , " Failed to rename ' \( source) ' to ' \( target) '. " , error)
@@ -221,10 +221,10 @@ class FileAccess: RCTEventEmitter {
221
221
func readFile( path: String , encoding: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
222
222
do {
223
223
if encoding == " base64 " {
224
- let binaryData = try Data ( contentsOf: URL ( fileURLWithPath: path) )
224
+ let binaryData = try Data ( contentsOf: URL ( fileURLWithPath: path. path ( ) ) )
225
225
resolve ( binaryData. base64EncodedString ( ) )
226
226
} else {
227
- try resolve ( String ( contentsOfFile: path) )
227
+ try resolve ( String ( contentsOfFile: path. path ( ) ) )
228
228
}
229
229
} catch {
230
230
reject ( " ERR " , " Failed to read ' \( path) '. " , error)
@@ -234,8 +234,8 @@ class FileAccess: RCTEventEmitter {
234
234
@objc ( stat: withResolver: withRejecter: )
235
235
func stat( path: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
236
236
do {
237
- let pathUrl = URL ( fileURLWithPath: path)
238
- let attrs = try FileManager . default. attributesOfItem ( atPath: path)
237
+ let pathUrl = URL ( fileURLWithPath: path. path ( ) )
238
+ let attrs = try FileManager . default. attributesOfItem ( atPath: path. path ( ) )
239
239
resolve ( [
240
240
" filename " : pathUrl. lastPathComponent,
241
241
" lastModified " : 1000 * ( attrs [ . modificationDate] as! NSDate ) . timeIntervalSince1970,
@@ -251,7 +251,7 @@ class FileAccess: RCTEventEmitter {
251
251
@objc ( unlink: withResolver: withRejecter: )
252
252
func unlink( path: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
253
253
do {
254
- try FileManager . default. removeItem ( atPath: path)
254
+ try FileManager . default. removeItem ( atPath: path. path ( ) )
255
255
resolve ( nil )
256
256
} catch {
257
257
reject ( " ERR " , " Failed to unlink ' \( path) '. " , error)
@@ -262,10 +262,10 @@ class FileAccess: RCTEventEmitter {
262
262
func writeFile( path: String , data: String , encoding: String , resolve: RCTPromiseResolveBlock , reject: RCTPromiseRejectBlock ) -> Void {
263
263
do {
264
264
if encoding == " base64 " {
265
- let pathUrl = URL ( fileURLWithPath: path)
265
+ let pathUrl = URL ( fileURLWithPath: path. path ( ) )
266
266
try Data ( base64Encoded: data) !. write ( to: pathUrl)
267
267
} else {
268
- try data. write ( toFile: path, atomically: false , encoding: . utf8)
268
+ try data. write ( toFile: path. path ( ) , atomically: false , encoding: . utf8)
269
269
}
270
270
resolve ( nil )
271
271
} catch {
@@ -275,7 +275,7 @@ class FileAccess: RCTEventEmitter {
275
275
276
276
private func checkIfIsDirectory( path: String ) -> ( exists: Bool , isDirectory: Bool ) {
277
277
var isDir : ObjCBool = false
278
- let exists = FileManager . default. fileExists ( atPath: path, isDirectory: & isDir)
278
+ let exists = FileManager . default. fileExists ( atPath: path. path ( ) , isDirectory: & isDir)
279
279
let isDirectory = isDir. boolValue
280
280
return ( exists, isDirectory)
281
281
}
0 commit comments