MCPcopy Create free account
hub / github.com/dataform-co/dataform / formatBytesInHumanReadableFormat

Function formatBytesInHumanReadableFormat

cli/util.ts:39–53  ·  view source on GitHub ↗
(bytes: number)

Source from the content-addressed store, hash-verified

37}
38
39export 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

Callers 2

printExecutedActionFunction · 0.90
util_test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected