unzipFile function

Future<bool> unzipFile(
  1. String path,
  2. String subdir
)

Implementation

Future<bool> unzipFile(String path, String subdir) async {
  final zipFile = File(path);
  final bytes = zipFile.readAsBytesSync();
  final archive = ZipDecoder().decodeBytes(bytes);

  for (final file in archive) {
    final filename = "$subdir/${file.name}";
    if (file.isFile) {
      final data = file.content as List<int>;
      final f = File(filename);
      await f.create(recursive: true);
      await f.writeAsBytes(data);
    } else {
      final dir = Directory(filename);
      await dir.create(recursive: true);
    }
  }
  return true;
}