12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- var Archiver = require('./lib/core');
- var formats = {};
- var vending = function(format, options) {
- return vending.create(format, options);
- };
- vending.create = function(format, options) {
- if (formats[format]) {
- var instance = new Archiver(format, options);
- instance.setFormat(format);
- instance.setModule(new formats[format](options));
- return instance;
- } else {
- throw new Error('create(' + format + '): format not registered');
- }
- };
- vending.registerFormat = function(format, module) {
- if (formats[format]) {
- throw new Error('register(' + format + '): format already registered');
- }
- if (typeof module !== 'function') {
- throw new Error('register(' + format + '): format module invalid');
- }
- if (typeof module.prototype.append !== 'function' || typeof module.prototype.finalize !== 'function') {
- throw new Error('register(' + format + '): format module missing methods');
- }
- formats[format] = module;
- };
- vending.registerFormat('zip', require('./lib/plugins/zip'));
- vending.registerFormat('tar', require('./lib/plugins/tar'));
- vending.registerFormat('json', require('./lib/plugins/json'));
- module.exports = vending;
|