Saturday 1 April 2017

nodejs - change contents of zip file without re-generating the whole archive

I'm using node-zip (which uses JSZip under the hood). I need to modify the contents of a zip file, and I'd love to be able to modify it without generating the entire zip again, because it can take a long time for large archives. Here's an example:

var zip = new JSZip()

// Add some files to the zip
zip.file('file1', "file 1 contents\n")
zip.file('file2', "file 2 contents\n")
zip.file('file3', "file 3 contents\n")

// Generate the zip file
buffer = zip.generate()

// Make some changes
zip.file('file1', "changed file contents\n")

// Now I have to generate the entire zip again to get the buffer
buffer = zip.generate()

How can I do something like

updatedBuffer = zip.updateFile(buffer, 'file1', 'changed file contents\n')

Where I get an updated archive buffer but I only have to spend CPU cycles updating the one file



via ZECTBynmo

No comments:

Post a Comment