MCPcopy Create free account
hub / github.com/appium/appium / toReadableSizeString

Function toReadableSizeString

packages/support/lib/util.ts:319–332  ·  view source on GitHub ↗
(bytes: number | string)

Source from the content-addressed store, hash-verified

317 * @throws {Error} If bytes cannot be converted to a non-negative integer
318 */
319export function toReadableSizeString(bytes: number | string): string {
320 const intBytes = parseInt(String(bytes), 10);
321 if (isNaN(intBytes) || intBytes < 0) {
322 throw new Error(`Cannot convert '${bytes}' to a readable size format`);
323 }
324 if (intBytes >= GiB) {
325 return `${(intBytes / (GiB * 1.0)).toFixed(2)} GB`;
326 } else if (intBytes >= MiB) {
327 return `${(intBytes / (MiB * 1.0)).toFixed(2)} MB`;
328 } else if (intBytes >= KiB) {
329 return `${(intBytes / (KiB * 1.0)).toFixed(2)} KB`;
330 }
331 return `${intBytes} B`;
332}
333
334/**
335 * Checks whether the given paths refer to the same file system entity (same device and inode).

Callers 5

writeFunction · 0.85
toInMemoryZipFunction · 0.85
uploadFileFunction · 0.85
downloadFileFunction · 0.85
writeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected