Skip to content

Commit

Permalink
add file unzip method
Browse files Browse the repository at this point in the history
  • Loading branch information
LiquidatorCoder committed Nov 26, 2021
1 parent cbfa7a7 commit d21541f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/services/zip_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,22 @@ class ZipService {
linkDesc = formatBytes(File(zipFilePath).lengthSync(), 2);
return File(zipFilePath);
}

Future<String> unzipFile(File file) async {
final archive = ZipDecoder().decodeBytes(file.readAsBytesSync());
final outDirectory = file.path.replaceAll('.zip', '') + '\\';
for (final zfile in archive) {
final filename = zfile.name;
if (zfile.isFile) {
final data = zfile.content as List<int>;
File(outDirectory + filename)
..createSync(recursive: true)
..writeAsBytesSync(data);
} else {
Directory(outDirectory + filename).create(recursive: true);
}
}
file.deleteSync(); // Delete the original ZIP file
return outDirectory;
}
}

0 comments on commit d21541f

Please sign in to comment.