Skip to content

Commit fbb9676

Browse files
committedMay 30, 2015
bring back parts of the existing instance vending code. bit too much breakage at once.
1 parent b48f4b4 commit fbb9676

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed
 

‎index.js

+36-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,42 @@
88

99
var Archiver = require('./lib/core');
1010

11-
module.exports = Archiver;
11+
var formats = {};
1212

13-
module.exports.create = function(format, options) {
14-
return new Archiver(format, options);
13+
var vending = module.exports = function(format, options) {
14+
return vending.create(format, options);
1515
};
1616

17-
module.exports.registerFormat = function(format, module) {
18-
throw new Error('registerFormat is no longer supported.');
19-
};
17+
module.exports.registerFormat = registerFormat;
18+
19+
function registerFormat(format, module) {
20+
if (formats[format]) {
21+
throw new Error('register(' + format + '): format already registered');
22+
}
23+
24+
if (typeof module !== 'function') {
25+
throw new Error('register(' + format + '): format module invalid');
26+
}
27+
28+
if (typeof module.prototype.append !== 'function' || typeof module.prototype.finalize !== 'function') {
29+
throw new Error('register(' + format + '): format module missing methods');
30+
}
31+
32+
formats[format] = module;
33+
}
34+
35+
vending.create = function(format, options) {
36+
if (formats[format]) {
37+
var instance = new Archiver(format, options);
38+
instance.setFormat(format);
39+
instance.setModule(new formats[format](options));
40+
41+
return instance;
42+
} else {
43+
throw new Error('create(' + format + '): format not registered');
44+
}
45+
};
46+
47+
registerFormat('zip', require('./lib/plugins/zip'));
48+
registerFormat('tar', require('./lib/plugins/tar'));
49+
registerFormat('json', require('./lib/plugins/json'));

‎lib/core.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ var Archiver = module.exports = function(format, options) {
5656
this._streams = [];
5757

5858
if (format === 'zip') {
59-
this.use(pzip());
59+
// this.use(pzip());
6060
} else if (format === 'tar') {
61-
this.use(ptar());
61+
// this.use(ptar());
6262
} else if (format === 'json') {
6363
this.use(pjson());
6464
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.