1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var ArchiverCore = require('./modules/core');
|
9 | var formatModules = {};
|
10 |
|
11 | var archiver = module.exports = function(format, options) {
|
12 | return archiver.create(format, options);
|
13 | };
|
14 |
|
15 | archiver.create = function(format, options) {
|
16 | if (formatModules[format]) {
|
17 | var inst = new ArchiverCore(options);
|
18 | inst.setModule(new formatModules[format](options));
|
19 |
|
20 | return inst;
|
21 | } else {
|
22 | throw new Error('unknown format: ' + format);
|
23 | }
|
24 | };
|
25 |
|
26 | archiver.registerFormat = function(format, module) {
|
27 | if (module && typeof module === 'function' && typeof module.prototype.append === 'function') {
|
28 | formatModules[format] = module;
|
29 |
|
30 |
|
31 | var compatName = 'create' + format.charAt(0).toUpperCase() + format.slice(1);
|
32 | archiver[compatName] = function(options) {
|
33 | return archiver.create(format, options);
|
34 | };
|
35 | } else {
|
36 | throw new Error('format module invalid: ' + format);
|
37 | }
|
38 | };
|
39 |
|
40 | archiver.registerFormat('zip', require('./modules/zip'));
|
41 | archiver.registerFormat('tar', require('./modules/tar'));
|
42 | archiver.registerFormat('json', require('./modules/json')); |
\ | No newline at end of file |