listTarFiles function

void listTarFiles(
  1. String path
)

Print the entries in the given tar file.

Implementation

void listTarFiles(String path) {
  final file = File(path);
  if (!file.existsSync()) {
    _fail('$path does not exist');
  }

  final input = InputFileStream(path);
  final dir = Directory.systemTemp.createTempSync('foo');
  final tempTarPath = '${dir.path}${Platform.pathSeparator}temp.tar';
  final output = OutputFileStream(tempTarPath);

  //List<int> data = file.readAsBytesSync();
  if (path.endsWith('tar.gz') || path.endsWith('tgz')) {
    GZipDecoder().decodeStream(input, output);
  } else if (path.endsWith('tar.bz2') || path.endsWith('tbz')) {
    BZip2Decoder().decodeStream(input, output);
  }

  final tarInput = InputFileStream(tempTarPath);

  final tarArchive = TarDecoder();
  // Tell the decoder not to store the actual file data since we don't need
  // it.
  tarArchive.decodeStream(tarInput, storeData: false);

  print('${tarArchive.files.length} file(s)');
  for (final f in tarArchive.files) {
    print('  $f');
  }
}