(bytes: number)
| 37 | } |
| 38 | |
| 39 | export function formatBytesInHumanReadableFormat(bytes: number): string { |
| 40 | // we do not want to raise an error when bytes < 0 |
| 41 | // because it will fail Dataform run command when in fact the BQ job was executed. |
| 42 | if (bytes <= 0) {return '0 B';} |
| 43 | |
| 44 | const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']; |
| 45 | const k = 1024; |
| 46 | |
| 47 | // Find the appropriate unit level |
| 48 | const i = Math.floor(Math.log(bytes) / Math.log(k)); |
| 49 | |
| 50 | const value = (bytes / Math.pow(k, i)).toFixed(2); |
| 51 | |
| 52 | return `${value} ${units[i]}`; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Handles prompting and validation for defaultBucketName, defaultTableFolderRoot |
no outgoing calls
no test coverage detected