tarDirectory method

Future<void> tarDirectory(
  1. Directory dir, {
  2. int compression = store,
  3. String? filename,
  4. bool followLinks = true,
  5. int? level,
  6. ZipFileProgress? filter,
})

Implementation

Future<void> tarDirectory(Directory dir,
    {int compression = store,
    String? filename,
    bool followLinks = true,
    int? level,
    ZipFileProgress? filter}) async {
  final dirPath = dir.path;
  if (compression == gzip || compression == zstd) {
    await _tarDirectoryCompressed(
      dir,
      filename ??
          (compression == gzip ? '$dirPath.tar.gz' : '$dirPath.tar.zst'),
      compression: compression,
      level: level,
      followLinks: followLinks,
      filter: filter,
    );
    return;
  }

  // An uncompressed TAR still writes directly to the target file.
  open(filename ?? '$dirPath.tar');
  try {
    await addDirectory(dir, followLinks: followLinks, filter: filter);
  } finally {
    await close();
  }
}