zipFiles method
压缩日志文件
Implementation
Future<File?> zipFiles(String? zipName) async {
final fileList = await getFileList();
if (fileList.isNotEmpty) {
final path = await getPlatformPath();
final encoder = ZipFileEncoder();
File zipFile;
if (zipName != null) {
zipFile = File('$path/$zipName.zip');
} else {
zipFile = File('$path/logs.zip');
}
final exists = await zipFile.exists();
if (exists) {
await zipFile.delete();
}
if (zipName != null) {
encoder.create('$path/$zipName.zip');
} else {
encoder.create('$path/logs.zip');
}
for (var element in fileList) {
await encoder.addFile(File(element.path));
}
// archive 3.6+ 的 close() 返回 Future<void>,须 await(异步收尾:
// 中央目录写完 zip 才完整)。
await encoder.close();
return zipFile;
}
return null;
}