tar function

Future<File> tar(
  1. FileCollection fileCollection, {
  2. required String destination,
  3. String destinationPath(
    1. String
    )?,
  4. Converter<List<int>, List<int>>? encoder,
})

Tar all files in the given fileCollection into the destination file.

The destination file is overwritten if it already exists.

If encoder is null (the default), the tarFile will be gzipped in case its name ends with either .tar.gz or .tgz, or use no further encoding otherwise.

Provide an encoder explicitly to use another encoding, or no encoding at all by using NoEncoding.

A destinationPath function can be provided to map source file paths into destination paths. That allows the path inside the tar archive to be chosen for each included file. By default, the path of the source file is also used for its destination path inside the tar.

The tar file is returned.

Implementation

Future<File> tar(FileCollection fileCollection,
    {required String destination,
    String Function(String)? destinationPath,
    Converter<List<int>, List<int>>? encoder}) async {
  logger.finer(() => 'Tar $fileCollection to $destination');
  final entries = _tarEntries(fileCollection.resolveFiles(), destinationPath);
  final dest = File(destination);
  await dest.parent.create(recursive: true);
  await entries
      .transform(tarWriter)
      .transform(encoder ?? gzip.encoder)
      .pipe(dest.openWrite());
  return dest;
}