parseDf static method
Parses POSIX df -k -P output into storage devices (sizes in 1 KiB
blocks). The header line is skipped.
Implementation
static List<StorageDevice> parseDf(String content) {
final lines = content.trim().split('\n');
final out = <StorageDevice>[];
for (final line in lines.skip(1)) {
final cols = line.trim().split(RegExp(r'\s+'));
if (cols.length < 6) continue;
final capacity = (int.tryParse(cols[1]) ?? 0) * 1024;
final available = (int.tryParse(cols[3]) ?? 0) * 1024;
final mount = cols.sublist(5).join(' ');
if (capacity == 0) continue;
out.add(
StorageDevice(
name: mount,
capacityBytes: capacity,
freeBytes: available,
),
);
}
return out;
}