untarToDirectory function
void
untarToDirectory(
- dynamic pathOrBytes,
- String destDir
)
Implementation
void untarToDirectory(dynamic pathOrBytes, String destDir) {
Uint8List bytes;
if (pathOrBytes is String) {
String zipPath = pathOrBytes;
zipPath = pathFullName(pathExpand(zipPath));
destDir = pathFullName(pathExpand(destDir));
bytes = dart_io.File(zipPath).readAsBytesSync();
} else if (pathOrBytes is Uint8List) {
bytes = pathOrBytes;
} else {
throw ArgumentError();
}
final archive = archive_archive.TarDecoder().decodeBytes(bytes);
for (final entry in archive) {
if (entry.isFile) {
var fileBytes = entry.readBytes();
fileBytes = fileBytes!;
if (isText(fileBytes)) {
String text = dart_convert.utf8.decode(fileBytes);
text = adjustTextNewlines(text);
fileBytes = dart_convert.utf8.encode(text);
}
writeFileBytes('$destDir/${entry.name}', fileBytes);
}
}
}