简体   繁体   English

Javascript下载多个文件并连接成一个文件

[英]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.

相关问题 从多个文件加载单个javascript文件 - Loading a single javascript file from multiple files 如何使用 fetch API 在 javascript 中下载具有多个块的单个文件 - How to download single file with multiple chunks in javascript using fetch API 将多个文件下载为 zip - javascript - download multiple files as zip - javascript 使用JavaScript下载多个文件 - Download multiple files using JavaScript Javascript使用iframe下载多个文件 - Javascript download multiple files with iframe 在Django项目中将多个JavaScript文件组合并压缩为单个文件 - Combining and Compressing multiple JavaScript files into a single file in a Django project 我需要将多个 JavaScript 文件合并压缩成一个 JS 文件 - I need to combine and compress multiple JavaScript files into a single JS file 一个javascript文件可以被多个html文件使用吗? - Can a single javascript file be used by multiple html files? 如何将来自不同文件夹的多个Javascript文件合并到一个文件中? - How to combine multiple Javascript files from different folder in a single file? 如何在按需构建的单个zip上下载多个文件(使用c#或javascript) - How to download multiple files on a single zip built on demand (using c# or javascript)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM