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));
}
encoder.close();
return zipFile;
}
return null;
}