Reactjs 下载zip,解包,将内容转换为srt,最后将str转换为数组
要下载zip文件,我正在使用Reactjs 下载zip,解包,将内容转换为srt,最后将str转换为数组,reactjs,react-native,axios,subtitle,jszip,Reactjs,React Native,Axios,Subtitle,Jszip,要下载zip文件,我正在使用Axios async getLegendaZip(url) { try { const response = await axios.get(url, { responseType: 'arraybuffer' }); this.unzipLegenda(response.data); } catch (error) { console.log(error); } } 要解压压缩文件,我正在使用JSzip 要将srt解析为数组我使用的是lib副标题
Axios
async getLegendaZip(url) {
try {
const response = await axios.get(url, { responseType: 'arraybuffer' });
this.unzipLegenda(response.data);
} catch (error) {
console.log(error);
}
}
要解压压缩文件,我正在使用JSzip
要将srt解析为数组
我使用的是lib副标题
unzipLegenda(buf) {
const new_zip = new JSZip();
new_zip.loadAsync(buf)
.then(function(zip) {
zip.forEach((relativePath, file) => {
const arr = parse(file);
console.log(arr);
});
});
}
我在日志中得到了这个警告
文件是一个字符串吗?它是一个图例。srt如果实际的buff是按我期望的方式解压的话。解析器需要一个字符串。因此,您已经从该文件中获取了内容。