javascript - 如何从 libarchive.js 获取解压缩文件和相应路径
问题描述
我正在尝试使用 archive.extractFiles 函数来获取路径和文件。此函数不等待列表数组填充,而是立即返回空数组。
import {Archive} from 'libarchive.js/main.js';
Archive.init({
workerUrl: '/libarchive.js/dist/worker-bundle.js'
});
public async getFileAndPath(fileList) {
const list = [];
console.log(fileList);
const archive = await Archive.open(fileList);
await archive.extractFiles(async entry => {
console.log(entry);
list.push(entry);
});
// console.log(obj);
return list;
}
How to make this function wait inside extractFiles.
解决方案
我相信回调函数不应该是异步的,你应该这样做
await archive.extractFiles(entry => {
console.log(entry);
list.push(entry);
});
顺便说一句,如果您需要整个阵列,您可以使用
return await archive.getFilesArray();
推荐阅读
- raspberry-pi - X735 电源管理与 X835 硬盘扩展板
- maven - Maven 原型创建一个 groovy 项目
- android - wfh时如何将移动应用程序连接到舞台环境服务器
- python - Python 中的数据清理 - 替换为 NaN
- sql - SQL Snowflake FILTER 函数 - 有条件地更新行
- sendgrid - 如何在 sendgrid 上使用 Web 链接 Substitution 标签?
- raspberry-pi - 为什么使用 distcc 编译 Python 时 make 会抛出错误?
- airflow - 气流工作者:他们怎么知道该怎么做?+ 问题
- vue.js - 如何从 Pull Request 分支预览组织 Github Pages 中的 vuepress 站点 - dev 分支
- java - 如何通过编程启用/禁用系统配置文件 - Android