unzip static method
Распаковка ZIP архива
Implementation
static Future<void> unzip(String srcPath, String dstPath) async {
final srcFile = File(srcPath);
if (!await srcFile.exists()) {
throw Exception('Source file does not exist: $srcPath');
}
final bytes = await srcFile.readAsBytes();
final archive = ZipDecoder().decodeBytes(bytes);
final dstDir = Directory(dstPath);
if (!await dstDir.exists()) {
await dstDir.create(recursive: true);
}
for (final file in archive) {
// Entry names are checked like the contract readers do (no absolute paths, drive letters or `..`).
if (!ComicsFileCodec.isSafeEntryName(file.name)) {
throw Exception('Unsafe archive entry: ${file.name}');
}
final filePath = path.join(dstPath, file.name);
final fileDir = Directory(path.dirname(filePath));
if (!await fileDir.exists()) {
await fileDir.create(recursive: true);
}
if (file.isFile) {
final outputFile = File(filePath);
await outputFile.writeAsBytes(file.content);
}
}
}