refactor and cleanup [skip ci]

This commit is contained in:
overtake
2019-11-01 17:11:12 +04:00
parent 66191348f3
commit 8f66c10ac1
786 changed files with 983 additions and 69155 deletions

View File

@@ -0,0 +1,21 @@
import Foundation
public func fileSize(_ path: String, useTotalFileAllocatedSize: Bool = false) -> Int? {
if useTotalFileAllocatedSize {
let url = URL(fileURLWithPath: path)
if let values = (try? url.resourceValues(forKeys: Set([.isRegularFileKey, .totalFileAllocatedSizeKey]))) {
if values.isRegularFile ?? false {
if let fileSize = values.totalFileAllocatedSize {
return fileSize
}
}
}
}
var value = stat()
if stat(path, &value) == 0 {
return Int(value.st_size)
} else {
return nil
}
}