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 badges2 Answers
Reset to default 7You 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条)