getProjectSize method
Calculates the size of the project at path.
Implementation
Future<ProjectSize> getProjectSize(String path) async {
int fileCount = 0;
int dirCount = 0;
int totalBytes = 0;
final byExtension = <String, int>{};
await for (final entity in Directory(
path,
).list(recursive: true, followLinks: false)) {
if (_shouldIgnore(entity.path)) continue;
if (entity is File) {
fileCount++;
try {
final size = await entity.length();
totalBytes += size;
final ext = _extension(entity.path);
byExtension[ext] = (byExtension[ext] ?? 0) + size;
} catch (_) {
// Permission denied, etc.
}
} else if (entity is Directory) {
dirCount++;
}
}
return ProjectSize(
fileCount: fileCount,
dirCount: dirCount,
totalBytes: totalBytes,
byExtension: byExtension,
);
}