tarDirectory method
Implementation
Future<void> tarDirectory(Directory dir,
{int compression = store,
String? filename,
bool followLinks = true,
int? level,
ZipFileProgress? filter}) async {
final dirPath = dir.path;
var tarPath = filename ?? '$dirPath.tar';
final tgzPath = filename ?? '$dirPath.tar.gz';
Directory tempDir;
if (compression == gzip) {
tempDir = await Directory.systemTemp.createTemp('dart_archive');
tarPath = '${tempDir.path}/temp.tar';
}
// Encode a directory from disk to disk, no memory
open(tarPath);
await addDirectory(Directory(dirPath),
followLinks: followLinks, filter: filter);
await close();
if (compression == gzip) {
final input = InputFileStream(tarPath);
final output = OutputFileStream(tgzPath);
GZipEncoder().encodeStream(input, output, level: level ?? 6);
await input.close();
await File(tarPath).delete();
}
}