How to write a file from an ArrayBuffer in JS

前端 未结 3 1342
花落未央
花落未央 2020-12-31 03:33

I am trying to write a file uploader for Meteor framework. The principle is to split the fileon the client from an ArrayBuffer in small packets of 4096 bits that are sent to

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 04:11

    Saving the file was as easy as creating a new Buffer with the Uint8Array object :

    // chunk is the Uint8Array object
    fs.appendFile(path, Buffer.from(chunk), function (err) {
        if (err) {
          fut.throw(err);
        } else {
          fut.return(chunk.length);
        }
    });
    

提交回复
热议问题