const zip = new JSZip();
const file = this.fileList[0];
const fileReader = new FileReader();
let invalidLines = [];
fileReader.onload = async (e) => {
const buffer = e.target.result;
await zip.loadAsync(buffer).then(async (zip) => {
const txtFile = Object.values(zip.files)[0];
await txtFile.async('text').then((content) => {
const lines = content.split('\n');
lines.forEach((line, index) => {
if (!/^[a-zA-Z0-9]*$/.test(line.trim())) {
invalidLines.push(index + 1);
}
});
});
});
}
// 代码逻辑
// ...
fileReader.readAsArrayBuffer(file);
npm install jszip
可以使用JSZip
库来读取zip文件 ,安装如上