archive.on('error', function(err) { rm(path.join(con.filePath,"temp",name),{},function (err) { }); throw err; });
archive.on('error', function(err){ reject(err); throw err; });
const baseUrl = `https://storage.googleapis.com/${process.env.GC_STORAGE}`; const archive = archiver('zip'); archive.on('warning', (err) => { if(err.code === 'ENOENT') { log.err(err, 'Archive Warning [ENOENT]'); archive.on('finish', (err) => { if(err) { log.error(err, 'Archive Error'); archive.on('error', (err) => { log.error(err, 'Archive Error'); });
//on stream closed we can end the request archive.on('end', function() { let b = archive.pointer() debug('Archive wrote %d bytes', b) if(!(data.stream instanceof http.ServerResponse)) { return self.ipc.send('archive:notify', user.username, { message: prettyBytes(b) + ' written in '+data.temp, path: p.dirname(data.temp), search: data.name + '.zip' }) } })
// https://github.com/archiverjs/node-archiver#quick-start export default function(directoryPath) { return new Promise((resolve, reject) => { const output = fs.createWriteStream(`${directoryPath}.zip`) output.on('close', resolve) output.on('end', resolve) const archive = archiver('zip') archive.on('error', reject) archive.on('warning', log.warn) archive.pipe(output) archive .directory(directoryPath, false) .finalize() }) }
// ------------------------------------------------------------- // Module. // ------------------------------------------------------------- function zip (name, destination, source, files) { if (files && files.length > 0) { const filename = path.join(destination, name) const output = fs.createWriteStream(filename) const archive = archiver('zip', { store: true }) archive.on('error', (err) => { throw err }) archive.pipe(output) files.forEach((f) => { archive.append(fs.createReadStream(path.join(source, f)), { name: f }) }) archive.finalize() return filename } }
archive.on('error', function(err) { archive.abort() if(!(data.stream instanceof http.ServerResponse)) { return self.ipc.send('archive:notify', user.username, {message: err.message, error: true}) } else { return data.stream.status(500).send(err); } })
const zip = (paths,cb) => { let output = fs.createWriteStream('share-it.zip'); //creates the zip in the same directory let archive = archiver('zip'); //just for information output.on('close',() => { console.info(archive.pointer() + ' total bytes'); console.info('archiver has been finalized and the output file descriptor has closed.'); cb() }); archive.on('error',(err) => { throw err }); archive.pipe(output); paths.split(",").forEach((path) => { archive.glob(path); //add files here }); console.info("Generating zip file, please wait. . . ") archive.finalize(); //generate the zip }
// good practice to catch this error explicitly archive.on('error', function(err) { console.log(err); });
archive.on('error', function(err){ throw err; });
archive.on('error', function (err) { throw err; });
archive.on('error', (err) => { throw err })
zip.on('error', (e)=>{ throw e; });