addDirectory method

  1. @override
Future<void> addDirectory(
  1. Directory dir, {
  2. bool includeDirName = true,
  3. int? level,
  4. bool followLinks = true,
  5. void onProgress(
    1. double
    )?,
})

Implementation

@override
Future<void> addDirectory(
  Directory dir, {
  bool includeDirName = true,
  int? level,
  bool followLinks = true,
  void Function(double)? onProgress,
}) async {
  final List files = dir.listSync(recursive: true, followLinks: followLinks);
  final futures = <Future<void>>[];
  final amount = files.length;
  int current = 0;
  for (final file in files) {
    if (file is! File) {
      continue;
    }
    final f = file;
    final dirName = path.basename(dir.path);
    final relativePath = path.relative(f.path, from: dir.path);
    futures.add(
      addFile(
        f,
        includeDirName ? ('$dirName/$relativePath') : relativePath,
        level,
      ).then((_) => onProgress?.call(++current / amount)),
    );
  }
  await Future.wait(futures);
}