mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
19 lines
488 B
TypeScript
19 lines
488 B
TypeScript
import { Pipe, PipeTransform } from '@angular/core'
|
|
|
|
// converts bytes to gigabytes
|
|
@Pipe({
|
|
name: 'convertBytes',
|
|
})
|
|
export class ConvertBytesPipe implements PipeTransform {
|
|
transform (bytes: number): string {
|
|
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(1)) + ' ' + sizes[i]
|
|
}
|
|
}
|