Skip to content

Commit e32d0cb

Browse files
authored
Merge pull request #334 from MAVERlCK/main
fix(ios): fix crash when processing file size of an unparsed URL
2 parents 0e316b3 + 222b1f4 commit e32d0cb

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

ios/Utils/Utils.swift

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,24 @@ class Utils {
110110
static func getfileSizeInBytes(forURL url: Any) -> Double {
111111
var fileURL: URL?
112112
var fileSize: Double = 0.0
113-
if (url is URL) || (url is String)
114-
{
115-
if (url is URL) {
116-
fileURL = url as? URL
117-
}
118-
else {
119-
fileURL = URL(fileURLWithPath: url as! String)
120-
}
121-
var fileSizeValue = 0.0
122-
try? fileSizeValue = (fileURL?.resourceValues(forKeys: [URLResourceKey.fileSizeKey]).allValues.first?.value as! Double?)!
123-
if fileSizeValue > 0.0 {
124-
fileSize = Double(fileSizeValue)
125-
}
113+
114+
if (url is URL) {
115+
let urlWithSlash = Utils.slashifyFilePath(path: (url as? URL)?.absoluteString)
116+
fileURL = URL(string: urlWithSlash!)
117+
} else if (url is String) {
118+
let urlWithSlash = Utils.slashifyFilePath(path: url as? String)
119+
fileURL = URL(fileURLWithPath: urlWithSlash!)
120+
} else {
121+
return fileSize
122+
}
123+
124+
var fileSizeValue = 0.0
125+
126+
try? fileSizeValue = (fileURL?.resourceValues(forKeys: [URLResourceKey.fileSizeKey]).allValues.first?.value as! Double?)!
127+
if fileSizeValue > 0.0 {
128+
fileSize = Double(fileSizeValue)
126129
}
130+
127131
return fileSize
128132
}
129133

0 commit comments

Comments
 (0)