【发布时间】:2020-01-16 19:53:45
【问题描述】:
我尝试使用 Flutter 中的 Archive 2.0.10 包来解压缩我的 zip 存档。可以,但是解压的时间相比安卓和iOS的原生功能来说是很长的(我这么说是因为我什至在安卓和iOS上都原生启动了这个应用),以及长时间锁定主线程。如果有人能帮助我实现这一点,我将不胜感激,以便我可以加快拆包速度。在 Pixel 3 Emulator (1536 MB Ram) 上进行测试需要大约 5 分钟或更长时间才能解压缩。如果我在 Flutter 上使用 Compute() 来隔离到另一个线程,Flutter 会返回“内存不足”错误。如果我在 Flutter 上使用 Platform View,在 Android 和 iOS 上尝试使用本机功能,我可以简化流程吗?谢谢!
这是我在 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);
}
}
【问题讨论】:
-
这里有同样的问题。 ZipDecoder decodeBytes 内存不足
-
我也有同样的问题。我所理解的是代码在到达
readAsBytesSync函数时停止工作。我还没有想出解决办法。你有吗?