Implementation
Future<void> addDirectory(Directory dir,
{bool includeDirName = true, int? level, bool followLinks = true}) async {
final dirName = path.basename(dir.path);
List files = dir.listSync(recursive: true, followLinks: followLinks);
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.addFile(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, level));
}
}
await Future.wait(futures);
}