从ZIP文件检索数据-NodeJS
本文介绍了从ZIP文件检索数据-NodeJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我问了自己一个问题
我可以在云平台上阅读文件(主要是CSV),但当它是压缩文件时,我只能得到一堆:
j�lȜ��&��3+xT��J��=��y��7���vu� {d�T���?��!�
这很正常,所以我想知道是否有办法将其放在一个变量中,然后使用lib或类似的东西将其解压缩。
感谢您抽出时间
推荐答案
您应该使用npm install node-stream-zip
const StreamZip = require('node-stream-zip');
const zip = new StreamZip({
file: 'archive.zip',
storeEntries: true
});
并像这样获取信息
zip.on('ready', () => {
console.log('Entries read: ' + zip.entriesCount);
for (const entry of Object.values(zip.entries())) {
const desc = entry.isDirectory ? 'directory' : `${entry.size} bytes`;
console.log(`Entry ${entry.name}: ${desc}`);
}
// Do not forget to close the file once you're done
zip.close()
});
希望对您有所帮助:-)
这篇关于从ZIP文件检索数据-NodeJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,