This repository has been archived on 2024-08-25. You can view files and clone it, but cannot push or open issues or pull requests.
Burgernotes-iOS/Burgernotes/Common/SizeHelper.swift

25 lines
634 B
Swift
Raw Normal View History

2024-02-29 17:38:44 +00:00
//
// SizeHelper.swift
// Burgernotes
//
// Created by ffqq on 28/02/2024.
//
// SIZE HELPER
//
// This is responsible for converting size (in bytes) to human-readable
// sizes (eg: 85 bytes, 12 kilobytes, 8 megabytes)
import Foundation
class SizeHelper {
func humanReadable(_ size: Int) -> String {
ByteCountFormatter().allowedUnits = [.useBytes, .useKB, .useMB, .useGB, .useTB]
ByteCountFormatter().countStyle = .file
return ByteCountFormatter().string(fromByteCount: Int64(size))
}
func humanReadable(_ size: String) -> String {
return humanReadable(Int(size) ?? 0)
}
}