The zipTree
function exported from this module takes a file tree object and creates a zip object from it using JSZip (which you need to install first via npm install jszip
):
// A tree is just a collection of file names mapped to their contents
let data = {
// Use a string for text content
'file.txt': '...file content...',
// Use a plain object for folders
'my-folder': {
'another-file.txt': '...file content...'
},
// Use other kinds of objects (e.g. Blob) to add binary data
'image': someBlob,
// Use an array to pass content and JSZip options
'with-options.txt': ['...file content...', { date: new Date(2012, 11, 21) }]
}
// Create the JSZip object
let zipObject = zipTree(data)
// Now save the zip object as you like, e.g. using FileSaver.js