package com.lanyun.wanglaotou.util

object TransferUtil {
    private var _transfer = 0.0
    private var _level = 0
    private val suffix = mutableListOf("B","KB","MB","GB","TB","PB")

    fun toHumanReadable(transfer : Int) :String{
        _transfer = transfer.toDouble()
        handleTransfer()
        return "$_transfer ${suffix[_level]}"
    }


    private fun handleTransfer() {
        if (_transfer > 1024) {
            _transfer /= 1024
            ++_level
            handleTransfer()
        }
    }
}