下载大文件 [英] Download big files
问题描述
我有一个文件表示为一个块列表,目标是下载所有块,加入并保存为文件。
I have a file represented as a list of chunks, and the goal is to download all chunks, join and save as a file.
- 它适用于大型文件
- 它应该是交叉的浏览器解决方案
- It should work for large files
- It should be cross-browser solution
我发现了什么......
What I've found...
- 使用JS数组
是的,我们可以在常规Javascript数组中下载和存储所有块。
- 这是跨浏览器的解决方案
- 但它使用RAM,如果文件大小超过可用内存浏览器,则崩溃。 ..
- 部分跨浏览器
- 有限文件尺寸
- 不跨浏览器
- 适合大型工作文件
- 这是Chrome沙箱文件系统api
- 适用于大型文件
但我还是无法实现目标满足要求...
如果有人有经验为了获得最佳解决方案,请在此处分享。谢谢
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
推荐答案
不幸的是,这里还没有真正的跨浏览器选项。
There isn't really a cross-browser option here yet unfortunately.
在Chrome中,您可以使用非标准文件系统API或Blob Chrome将使用该文件系统如果blob很大。
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.
在Firefox中,您可以使用非标准IDBMutableFile 。但是,它不适用于下载API ,所以你会必须使用 window.location
将浏览器发送到blob URL,然后浏览器必须下载该URL(所有文件扩展名可能不会发生)。您还可能需要使用 IDB持久性选项文件大于~2GB。
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.
在其他浏览器中,Blob是您唯一真正的选择。另一方面,运行浏览器的操作系统可能会使用分页,这可能会使浏览器创建大于内存的blob 。
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.
像StreamSaver这样基于服务工作者的选项也可能有所帮助(也许这可能是Firefox的下载API替代方案),但浏览器等待完整响应的时间有限(或者是?),这意味着你可能会必须在某个地方下载并存储块以及时完成响应。
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 complete response, meaning you would probably have to download and store the chunks somewhere to complete the response in time.
这篇关于下载大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!