task.plugin('zip', { every:false }, function * (files, opts) { opts = Object.assign({ file:'archive.zip' }, opts); let curr; for (const file of files) { if (file.data) { curr = p.relative(task.root, p.format(file)); zip.file(curr, file.data, { base64:true }); } } const outdata = yield zip.generateAsync({ type:'nodebuffer' }); // if an alt `dest` was given if (opts.dest !== void 0) { // write file without overwriting files const outfile = p.resolve(task.root, opts.dest, opts.file); yield utils.write(outfile, outdata); } else { // overwrite with the archive this._.files = [{ dir: files[0].dir, base: opts.file, data: outdata }]; } });
// Export each model queue.push( models[model].findAll() .then((rows) => { let data = []; if(rows.length) { rows.forEach((row) => data.push(row.toJSON())); } // Write data to zip file zip.folder('data').file(model + '.json', JSON.stringify(data, null, 2)); }) .catch((err) => next(err)) );
function packfiles (directory) { const files = fs.readdirSync(directory) for (let i = 0; i < files.length; i++) { const file = files[i] const filepath = path.join(directory, file) let invalid = false for (let j = 0; j < ignoreFiles.length; j++) { const ignoreFile = path.join(__dirname, '..', ignoreFiles[j]).replace(/{\.}/g, '.') if (filepath.substr(0, ignoreFile.length) === ignoreFile) { invalid = true break } } if (invalid) { continue } const stat = fs.statSync(filepath) const relative = path.relative(rootDir, filepath).replace(/\\/g, '/') if (stat.isDirectory()) { zipArchive.folder(relative) packfiles(filepath) } else { zipArchive.file(relative, fs.readFileSync(filepath)) } } }
}, function(tileDone) { GeoPackage.getTileFromXYZ(geopackage, name, xTile, yTile, zoom, 256, 256, function(err, tile) { zip.file(zoom+'/'+xTile+'/'+yTile+'.png', tile); yTile++; tileDone();
.then(zip => { return Promise.all([ zip.file('document.json').async('string'), zip.file('meta.json').async('string'), zip.file('user.json').async('string') ]).then(result => { return { return Promise.all( data.document.pages.map(page => { return data.repo.file(`${page._ref}.json`).async('string'); }) ).then(pages => {