Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /**
  58. * Check if the format is already registered.
  59. *
  60. * @param {String} format the name of the format.
  61. * @return boolean
  62. */
  63. vending.isRegisteredFormat = function (format) {
  64. if (formats[format]) {
  65. return true;
  66. }
  67. return false;
  68. };
  69. vending.registerFormat('zip', require('./lib/plugins/zip'));
  70. vending.registerFormat('tar', require('./lib/plugins/tar'));
  71. vending.registerFormat('json', require('./lib/plugins/json'));
  72. module.exports = vending;