admin管理员组文章数量:1325720
I have a file represented as a list of chunks, and the goal is to download all chunks, join and save as a file.
Requirements
- It should work for large files
- It should be cross-browser solution
What I've found...
- Use JS Array
Yes, we can download and store all chunks in regular Javascript array.- It's cross-browser solution
- But it uses RAM, and if file size exceeds free memory browser just crashes...
- FileSaver.js
- Partly cross-browser
- Limited file size
- StreamSaver.js
- Not cross-browser
- Works for large files
- Filesystem API
- It's Chrome sandbox filesystem api
- Works for large files
But I still can't achieve my goal with covered requirements...
If someone has experience for best solution I kindly ask to share it here. Thanks
I have a file represented as a list of chunks, and the goal is to download all chunks, join and save as a file.
Requirements
- It should work for large files
- It should be cross-browser solution
What I've found...
- Use JS Array
Yes, we can download and store all chunks in regular Javascript array.- It's cross-browser solution
- But it uses RAM, and if file size exceeds free memory browser just crashes...
- FileSaver.js
- Partly cross-browser
- Limited file size
- StreamSaver.js
- Not cross-browser
- Works for large files
- Filesystem API
- It's Chrome sandbox filesystem api
- Works for large files
But I still can't achieve my goal with covered requirements...
If someone has experience for best solution I kindly ask to share it here. Thanks
- do you have to dl the chunks in JS? if you spit it out from the server as a download the browser will collect all that into an unprocessed file. the other option is downloading chunks and re-bining them locally, outside of the browser, maybe with a simple cat or, fancier, multiple zip files on a single archive. – dandavis Commented Dec 13, 2017 at 22:14
- I have to join chunks in browser and save as a file – Rashad Ibrahimov Commented Dec 13, 2017 at 22:22
1 Answer
Reset to default 5There isn't really a cross-browser option here yet unfortunately.
In Chrome, you can use either the non-standard Filesystem API, or Blobs which Chrome will use the file-system for if the blob is large.
In Firefox, you can use maybe use the non-standard IDBMutableFile. However, it will not work with the download API, so you would have to use window.location
to send the browser to the blob URL, which the browser must then download (may not happen for all file extensions). You also may need to use the IDB persistent option to have files larger than ~2GB.
In other browsers, Blob is your only real option. On the up side, the OS the browser runs on may use paging which could enable the browser to create blobs larger than memory.
A service-worker-based option like StreamSaver may also help (perhaps this could be a download API alternative for Firefox), but there is (or was?) a limit to how long the browser will wait for a plete response, meaning you would probably have to download and store the chunks somewhere to plete the response in time.
本文标签: javascriptDownload big filesStack Overflow
版权声明:本文标题:javascript - Download big files - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742194642a2430850.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论