addDirectory method

Future<void> addDirectory(
  1. Directory dir, {
  2. bool followLinks = true,
  3. bool includeDirName = true,
})

Implementation

Future<void> addDirectory(Directory dir,
    {bool followLinks = true, bool includeDirName = true}) async {
  final files = dir.listSync(recursive: true, followLinks: followLinks);

  final dirName = path.basename(dir.path);
  var futures = <Future<void>>[];
  for (var file in files) {
    if (file is Directory) {
      var filename = path.relative(file.path, from: dir.path);
      filename = includeDirName ? '$dirName/$filename' : filename;
      final af = ArchiveFile('$filename/', 0, null);
      af.mode = file.statSync().mode;
      af.isFile = false;
      _encoder.add(af);
    } else if (file is File) {
      final dirName = path.basename(dir.path);
      final relPath = path.relative(file.path, from: dir.path);
      futures
          .add(addFile(file, includeDirName ? '$dirName/$relPath' : relPath));
    }
  }

  await Future.wait(futures);
}