UNPKG

1.32 kBJavaScriptView Raw
1/**
2 * node-archiver
3 *
4 * Copyright (c) 2012-2014 Chris Talkington, contributors.
5 * Licensed under the MIT license.
6 * https://github.com/ctalkington/node-archiver/blob/master/LICENSE-MIT
7 */
8var ArchiverCore = require('./modules/core');
9var formatModules = {};
10
11var archiver = module.exports = function(format, options) {
12 return archiver.create(format, options);
13};
14
15archiver.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
26archiver.registerFormat = function(format, module) {
27 if (module && typeof module === 'function' && typeof module.prototype.append === 'function') {
28 formatModules[format] = module;
29
30 // backwards compat
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
40archiver.registerFormat('zip', require('./modules/zip'));
41archiver.registerFormat('tar', require('./modules/tar'));
42archiver.registerFormat('json', require('./modules/json'));
\No newline at end of file