UNPKG

@controlplane/cli

Version:

Control Plane Corporation CLI

33 lines 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.detectTarErrorOrWarning = exports.humanReadableSize = void 0; function humanReadableSize(bytes) { if (bytes >= 2 ** 30) { return { value: (bytes / 2 ** 30).toFixed(2), unit: 'GB' }; } else if (bytes >= 2 ** 20) { return { value: (bytes / 2 ** 20).toFixed(2), unit: 'MB' }; } else if (bytes >= 2 ** 10) { return { value: (bytes / 2 ** 10).toFixed(2), unit: 'KB' }; } return { value: bytes.toString(), unit: 'Bytes' }; } exports.humanReadableSize = humanReadableSize; function detectTarErrorOrWarning(data) { // Convert buffer to UTF-8 string const text = data.toString('utf8').trim(); // Check for tar errors (multi-line or single-line) if (/tar:\s*(error|cannot|failed|stat|invalid|not found|exiting)/i.test(text) || /tar:\s*Exiting with failure status due to previous errors/i.test(text)) { return 'error'; } // Check for tar warnings (multi-line or single-line) if (/tar:\s*(warning|skipping|ignoring|deprecated|removing leading `\/')/i.test(text)) { return 'warning'; } // If no match, return null return null; } exports.detectTarErrorOrWarning = detectTarErrorOrWarning; //# sourceMappingURL=helpers.js.map