2021-05-17 19:58:33 +02:00
|
|
|
const base64ToString = (str: string) => Buffer.from(str, 'base64').toString('utf-8')
|
|
|
|
const stringToBase64 = (str: string) => Buffer.from(str, 'utf-8').toString('base64')
|
|
|
|
|
2021-05-17 19:58:58 +02:00
|
|
|
const formatBytes = (bytes: number, decimals = 2) => {
|
|
|
|
if (bytes === 0) {
|
|
|
|
return '0 Bytes'
|
|
|
|
}
|
|
|
|
|
|
|
|
const k = 1024
|
|
|
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
|
|
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
|
|
|
|
|
|
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + ' ' + sizes[i]
|
|
|
|
}
|
|
|
|
|
2021-05-17 19:58:33 +02:00
|
|
|
export {
|
|
|
|
stringToBase64,
|
2021-05-17 19:58:58 +02:00
|
|
|
base64ToString,
|
|
|
|
formatBytes
|
2021-05-17 19:58:33 +02:00
|
|
|
}
|