Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("should raises an error when don't pass a second required argument", () => {
// $ExpectError (must pass in a module)
Archiver.registerFormat('zip');
});
});
before(() => {
try {
archiver.registerFormat('zip-encrypted', require('../'));
} catch (e) {
// already registered
}
});
before(() => {
try {
archiver.registerFormat('zip-encrypted', require('../lib/zip-encrypted'));
} catch (e) {
// already registered
}
});
Archiver("zip", { gzp: true });
Archiver("zip", { gzip: true });
// $ExpectError (values of options should use correct type)
Archiver("zip", { statConcurrency: "1" });
Archiver("zip", { statConcurrency: 1 });
// $ExpectError (must pass in a format)
Archiver.create();
Archiver.create("zip");
Archiver.create("zip", {});
// $ExpectError (must pass in a format and module)
Archiver.registerFormat();
// $ExpectError (must pass in a module)
Archiver.registerFormat("zip");
Archiver.registerFormat("zip", () => {});
const options = {
statConcurrency: 1,
allowHalfOpen: true,
readableObjectMode: true,
writeableObjectMode: true,
decodeStrings: true,
encoding: "test",
highWaterMark: 1,
objectmode: true,
comment: "test",
forceLocalTime: true,
forceZip64: true,
store: true,
zlib: {},
output.on('end', function () { });
archive.on('warning', function (err) { console.log('Backup warning: ' + err); });
archive.on('error', function (err) { console.log('Backup error: ' + err); });
archive.pipe(output);
archive.file(newBackupPath + '.archive', { name: newBackupFile + '.archive' });
archive.directory(parent.datapath, 'meshcentral-data');
archive.finalize();
} catch (ex) { console.log(ex); }
});
} else {
// Perform a NeDB backup
var archiver = require('archiver');
var output = parent.fs.createWriteStream(newAutoBackupPath + '.zip');
var archive = null;
if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.zippassword == 'string')) {
try { archiver.registerFormat('zip-encrypted', require("archiver-zip-encrypted")); } catch (ex) { }
archive = archiver.create('zip-encrypted', { zlib: { level: 9 }, encryptionMethod: 'aes256', password: parent.config.settings.autobackup.zippassword });
} else {
archive = archiver('zip', { zlib: { level: 9 } });
}
output.on('close', function () { obj.performingBackup = false; });
output.on('end', function () { });
archive.on('warning', function (err) { console.log('Backup warning: ' + err); });
archive.on('error', function (err) { console.log('Backup error: ' + err); });
archive.pipe(output);
archive.directory(parent.datapath, 'meshcentral-data');
archive.finalize();
}
// Remove old backups
if (parent.config.settings.autobackup && (typeof parent.config.settings.autobackup.keeplastdaysbackup == 'number')) {
var cutoffDate = new Date();
s3Zip.archiveStream = function (stream, filesS3, filesZip) {
const self = this
const folder = this.folder || ''
if (this.registerFormat) {
archiver.registerFormat(this.registerFormat, this.formatModule)
}
const archive = archiver(this.format || 'zip', this.archiverOpts || {})
archive.on('error', function (err) {
self.debug && console.log('archive error', err)
})
stream
.on('data', function (file) {
if (file.path[file.path.length - 1] === '/') {
self.debug && console.log('don\'t append to zip', file.path)
return
}
let fname
if (filesZip) {
// Place files_s3[i] into the archive as files_zip[i]
const i = filesS3.indexOf(file.path.startsWith(folder) ? file.path.substr(folder.length) : file.path)
fname = (i >= 0 && i < filesZip.length) ? filesZip[i] : file.path
var expect = require('chai').expect;
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var temp = require('temp').track();
var archiver = require('archiver');
var readline = require('readline');
var PassThrough = require('stream').PassThrough;
archiver.registerFormat('zip-encryptable', require('../'));
function slice(content, begin, size) {
return content.slice(begin, begin + size);
}
function bytes(array) {
return Buffer.from(array);
}
describe('archive', function() {
before(function() {
temp.track();
});
it('archives flies with password', function(done) {
var tempDir = temp.mkdirSync('out');
exports.handler = async (event) => {
const bucket = process.env['BUCKET'];
const password = process.env['PASSWORD'];
if (!bucket || !password) {
console.log('bucket and password is required');
return;
}
var aws = require('aws-sdk');
var s3 = new aws.S3();
var archiver = require('archiver');
var PassThrough = require('stream').PassThrough;
archiver.registerFormat(
'zip-encryptable',
require('archiver-zip-encryptable')
);
var passThrough = new PassThrough();
var archive = archiver('zip-encryptable', {
password: password
});
archive.pipe(passThrough);
for (var i = 1; i <= 20; i++) {
archive.append(
s3.getObject({ Bucket: bucket, Key: 'test1.txt' }).createReadStream(),
{
name: `test${i}.txt`
}
);
var fs = require('fs');
var archiver = require('archiver');
archiver.registerFormat('zip-encryptable', require('archiver-zip-encryptable'));
var output = fs.createWriteStream(__dirname + '/example.zip');
var archive = archiver('zip-encryptable', {
zlib: { level: 9 },
forceLocalTime: true,
password: 'test'
});
archive.pipe(output);
archive.append(Buffer.from('Hello World'), { name: 'test.txt' });
archive.append(Buffer.from('Good Bye'), { name: 'test2.txt' });
archive.finalize();
import React from 'react';
import ReactDOM from 'react-dom';
import archiver from 'archiver';
import AdmZip from 'adm-zip';
import PluginSettings from './containers/PluginSettings';
archiver.registerFormat('zip-encryptable', require('archiver-zip-encryptable'));
const checkIfSingleArchive = ({ filePaths, path }) => ((filePaths.length === 1 && path.parse(filePaths[0]).ext === '.zip') || false);
const getFilePaths = async ({
path,
filePaths,
isSingleArchive,
createNewFile,
readFilePath,
}) => {
const parsedPath = path.parse(filePaths[0]);
if (isSingleArchive && !createNewFile) {
return { filePath: filePaths[0], dirPath: parsedPath.dir };
}
const paths = await readFilePath({
title: 'Select save directory',