javascript - Editing a file within a zipped file using JSZip - Stack Overflow

Using JSZip, is there a way to edit a file within a zipped file?I've tried looking for solutions a

Using JSZip, is there a way to edit a file within a zipped file?

I've tried looking for solutions and going through the API but I can't seem to find a solution.

Any help with this would be great! Thanks in advance!

Using JSZip, is there a way to edit a file within a zipped file?

I've tried looking for solutions and going through the API but I can't seem to find a solution.

Any help with this would be great! Thanks in advance!

Share Improve this question asked Nov 23, 2016 at 20:53 Dowling1dowDowling1dow 571 silver badge6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

You can edit a file inside your zip with .file method.

zip.file("existing_filename", "new file content");

This method is used for adding and updating file content.

Just make sure the file already exist.

You can read more about it in the documentation.

You can refer to the official documentation.

And here's a more plete Node.js example:

var fs = require("fs");
var JSZip = require("jszip");

async function zipDemo() {
    // read the existing zip file
    var zipData = fs.readFileSync("input.zip");
    var zip = await JSZip.loadAsync(zipData);
    // add a new JSON file to the zip
    zip.file("sample.json", JSON.stringify({demo:123}));
    // write out the updated zip
    zip.generateNodeStream({type:'nodebuffer', streamFiles:true})
    .pipe(fs.createWriteStream('output.zip'))
    .on('finish', function () {
        console.log("output`enter code here`.zip written.");
    });
}

zipDemo();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744876906a4598600.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信