我尝试在Flutter中使用Archive 2.0.10包来解压我的zip文件。它可以运行,但与Android和iOS的本地函数相比,解压时间很长(因为我甚至已经在Android和iOS的本机应用程序中启动了它),同时还会长时间锁定主线程。如果有人帮助我实现这一点,以便我可以加快解压缩速度,我将不胜感激。在Pixel 3模拟器(1536 MB RAM)上测试需要大约5分钟或更长时间才能解压缩。如果我在Flutter上使用Compute()来独立到另一个线程,Flutter会返回“内存不足”错误。如果我在Flutter上使用Platform View来尝试在Android和iOS上使用本地函数,那么我能否简化这个过程呢?谢谢!
以下是我在Flutter中使用的函数:
以下是我在Flutter中使用的函数:
unZipFile() async {
try{
String path = await getDatabasesPath();
String fileZip = ConstData.fileDBZip;
// Le o arquivo Zip no disco
List<int> bytes = new File("$path/$fileZip").readAsBytesSync();
// Decodifica o arquivo Zip
Archive archive = new ZipDecoder().decodeBytes(bytes);
// Descompacta o arquivo Zip para o disco
for (ArchiveFile file in archive) {
String filename = "$path/${file.name}";
if (file.isFile) {
final decompressed = await compute(decompressArchiveFile, file); // file.content;
new File(filename)
..createSync(recursive: true)
..writeAsBytesSync(decompressed);
} else {
await new Directory(filename).create(recursive: true);
}
}
}catch(e){
print(e);
}
}
readAsBytesSync
函数时停止工作。我还没有想出解决方案。你有吗? - Navid All Gharaee