[英]Javascript download multiple files and concatenate into a single file
I am supporting a website development work. 我支持网站开发工作。 Two binary files are downloaded to client browser upon request.
根据请求将两个二进制文件下载到客户端浏览器。 The two files can come from two different sources.
这两个文件可以来自两个不同的来源。
The requirement is to concatenate both the files into a single file. 要求是将两个文件连接成一个文件。 Creating a single file in JavaScript and writing first downloaded content followed by second downloaded content is also acceptable.
在JavaScript中创建单个文件并编写第一个下载的内容,然后是第二个下载的内容也是可以接受的。
Is this doable in JavaScript using FileAPI or any other related APIs? 这在JavaScript中使用FileAPI或任何其他相关API是否可行?
Do I need to explore Chrome/Firefox Extension to achieve the same? 我是否需要探索Chrome / Firefox扩展才能实现相同目标?
I'm not sure what you're trying to do but if I understood correctly you can store your files into ArrayBuffers
and then merge them: 我不确定你要做什么但如果我理解正确你可以将你的文件存储到
ArrayBuffers
然后合并它们:
/**
* Creates a new Uint8Array based on two different ArrayBuffers
*
* @private
* @param {ArrayBuffers} buffer1 The first buffer.
* @param {ArrayBuffers} buffer2 The second buffer.
* @return {ArrayBuffers} The new ArrayBuffer created out of the two.
*/
var _appendBuffer = function(buffer1, buffer2) {
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
tmp.set(new Uint8Array(buffer1), 0);
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
return tmp.buffer;
};
Source: https://gist.github.com/72lions/4528834 资料来源: https : //gist.github.com/72lions/4528834
Here you can read more about ArrayBuffers
and you definitely should check MDN's Sending and Receiving Binary Data 在这里,您可以阅读有关
ArrayBuffers
更多信息,您肯定应该检查MDN的发送和接收二进制数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.