zipster
Version:
TypeScript library built for Node backends to create ZIP files with password protection
46 lines • 1.96 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
const archiverZipEncryptable = require("archiver-zip-encryptable");
const archiver_1 = require("archiver");
const Formats_1 = require("../enums/Formats");
const ZipsterError_1 = require("../errors/ZipsterError");
/**
* Archiver Factory creates an archiver instance configured with specified options
*/
class ArchiverFactory {
/**
* Get a configured archiver instance
*/
static getArchiver(options) {
const { format } = options, rest = __rest(options, ["format"]);
const archiverOptions = Object.assign({ forceLocalTime: true, zlib: {
level: 9
} }, rest);
if (options.format === Formats_1.Formats.ZIP || options.format === Formats_1.Formats.TAR) {
return archiver_1.create(options.format, archiverOptions);
}
if (options.format === Formats_1.Formats.ZIP_ENCRYPTED) {
this.registerZipEncryptable();
return archiver_1.create(options.format, archiverOptions);
}
throw new ZipsterError_1.ZipsterError('Unknown archiver format');
}
static registerZipEncryptable() {
if (!archiver_1.isRegisteredFormat(Formats_1.Formats.ZIP_ENCRYPTED)) {
archiver_1.registerFormat(Formats_1.Formats.ZIP_ENCRYPTED, archiverZipEncryptable);
}
}
}
exports.ArchiverFactory = ArchiverFactory;
//# sourceMappingURL=ArchiverFactory.js.map