admin管理员组文章数量:1306238
I am extracting a zip file with JSZip by doing the following:
jszip.loadAsync(zipFile)
['then'](function(zip) {
return bluebird.map(Object.keys(zip.files), function (filename) {
// converts the pressed file to a string of its contents
return zip.files[filename].async('string').then(function (fileData) {
// fileData is a string of the contents
})
})
})
However, the output of this extraction is an array of strings of the file contents. I was wondering if it was possible to get an array of file objects as the output instead because I need the file object later.
I have tried to do
new File(fileData.split('\n'), filename)
But it loses the original file formatting.
Any suggestions?
I am extracting a zip file with JSZip by doing the following:
jszip.loadAsync(zipFile)
['then'](function(zip) {
return bluebird.map(Object.keys(zip.files), function (filename) {
// converts the pressed file to a string of its contents
return zip.files[filename].async('string').then(function (fileData) {
// fileData is a string of the contents
})
})
})
However, the output of this extraction is an array of strings of the file contents. I was wondering if it was possible to get an array of file objects as the output instead because I need the file object later.
I have tried to do
new File(fileData.split('\n'), filename)
But it loses the original file formatting.
Any suggestions?
Share Improve this question asked Mar 3, 2017 at 19:43 tgreentgreen 1,9361 gold badge18 silver badges32 bronze badges1 Answer
Reset to default 10The File
constructor takes a list of BufferSource (ArrayBuffer, Uint8Array, etc), Blob or string. If you split the content on \n
, you will remove these \n
. File
will then concatenate each string without re-adding the new lines.
Use a blob instead:
return zip.files[filename].async('blob').then(function (fileData) {
return new File([fileData], filename);
})
本文标签: javascriptJSZip extract file objectsStack Overflow
版权声明:本文标题:javascript - JSZip extract file objects - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741818292a2399210.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论