Front end of the Slack clone application.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * Archiver Vending
  3. *
  4. * @ignore
  5. * @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
  6. * @copyright (c) 2012-2014 Chris Talkington, contributors.
  7. */
  8. var Archiver = require('./lib/core');
  9. var formats = {};
  10. /**
  11. * Dispenses a new Archiver instance.
  12. *
  13. * @constructor
  14. * @param {String} format The archive format to use.
  15. * @param {Object} options See [Archiver]{@link Archiver}
  16. * @return {Archiver}
  17. */
  18. var vending = function(format, options) {
  19. return vending.create(format, options);
  20. };
  21. /**
  22. * Creates a new Archiver instance.
  23. *
  24. * @param {String} format The archive format to use.
  25. * @param {Object} options See [Archiver]{@link Archiver}
  26. * @return {Archiver}
  27. */
  28. vending.create = function(format, options) {
  29. if (formats[format]) {
  30. var instance = new Archiver(format, options);
  31. instance.setFormat(format);
  32. instance.setModule(new formats[format](options));
  33. return instance;
  34. } else {
  35. throw new Error('create(' + format + '): format not registered');
  36. }
  37. };
  38. /**
  39. * Registers a format for use with archiver.
  40. *
  41. * @param {String} format The name of the format.
  42. * @param {Function} module The function for archiver to interact with.
  43. * @return void
  44. */
  45. vending.registerFormat = function(format, module) {
  46. if (formats[format]) {
  47. throw new Error('register(' + format + '): format already registered');
  48. }
  49. if (typeof module !== 'function') {
  50. throw new Error('register(' + format + '): format module invalid');
  51. }
  52. if (typeof module.prototype.append !== 'function' || typeof module.prototype.finalize !== 'function') {
  53. throw new Error('register(' + format + '): format module missing methods');
  54. }
  55. formats[format] = module;
  56. };
  57. vending.registerFormat('zip', require('./lib/plugins/zip'));
  58. vending.registerFormat('tar', require('./lib/plugins/tar'));
  59. vending.registerFormat('json', require('./lib/plugins/json'));
  60. module.exports = vending;