Skip to content

Commit

Permalink
bring back parts of the existing instance vending code. bit too much …
Browse files Browse the repository at this point in the history
…breakage at once.
  • Loading branch information
ctalkington committed May 30, 2015
1 parent b48f4b4 commit fbb9676
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
42 changes: 36 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,42 @@

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

module.exports = Archiver;
var formats = {};

module.exports.create = function(format, options) {
return new Archiver(format, options);
var vending = module.exports = function(format, options) {
return vending.create(format, options);
};

module.exports.registerFormat = function(format, module) {
throw new Error('registerFormat is no longer supported.');
};
module.exports.registerFormat = registerFormat;

function registerFormat(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.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');
}
};

registerFormat('zip', require('./lib/plugins/zip'));
registerFormat('tar', require('./lib/plugins/tar'));
registerFormat('json', require('./lib/plugins/json'));
4 changes: 2 additions & 2 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ var Archiver = module.exports = function(format, options) {
this._streams = [];

if (format === 'zip') {
this.use(pzip());
// this.use(pzip());
} else if (format === 'tar') {
this.use(ptar());
// this.use(ptar());
} else if (format === 'json') {
this.use(pjson());
} else {
Expand Down

0 comments on commit fbb9676

Please sign in to comment.