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.

json.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * JSON Format Plugin
  3. *
  4. * @module plugins/json
  5. * @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
  6. * @copyright (c) 2012-2014 Chris Talkington, contributors.
  7. */
  8. var inherits = require('util').inherits;
  9. var Transform = require('readable-stream').Transform;
  10. var crc32 = require('buffer-crc32');
  11. var util = require('archiver-utils');
  12. /**
  13. * @constructor
  14. * @param {(JsonOptions|TransformOptions)} options
  15. */
  16. var Json = function(options) {
  17. if (!(this instanceof Json)) {
  18. return new Json(options);
  19. }
  20. options = this.options = util.defaults(options, {});
  21. Transform.call(this, options);
  22. this.supports = {
  23. directory: true,
  24. symlink: true
  25. };
  26. this.files = [];
  27. };
  28. inherits(Json, Transform);
  29. /**
  30. * [_transform description]
  31. *
  32. * @private
  33. * @param {Buffer} chunk
  34. * @param {String} encoding
  35. * @param {Function} callback
  36. * @return void
  37. */
  38. Json.prototype._transform = function(chunk, encoding, callback) {
  39. callback(null, chunk);
  40. };
  41. /**
  42. * [_writeStringified description]
  43. *
  44. * @private
  45. * @return void
  46. */
  47. Json.prototype._writeStringified = function() {
  48. var fileString = JSON.stringify(this.files);
  49. this.write(fileString);
  50. };
  51. /**
  52. * [append description]
  53. *
  54. * @param {(Buffer|Stream)} source
  55. * @param {EntryData} data
  56. * @param {Function} callback
  57. * @return void
  58. */
  59. Json.prototype.append = function(source, data, callback) {
  60. var self = this;
  61. data.crc32 = 0;
  62. function onend(err, sourceBuffer) {
  63. if (err) {
  64. callback(err);
  65. return;
  66. }
  67. data.size = sourceBuffer.length || 0;
  68. data.crc32 = crc32.unsigned(sourceBuffer);
  69. self.files.push(data);
  70. callback(null, data);
  71. }
  72. if (data.sourceType === 'buffer') {
  73. onend(null, source);
  74. } else if (data.sourceType === 'stream') {
  75. util.collectStream(source, onend);
  76. }
  77. };
  78. /**
  79. * [finalize description]
  80. *
  81. * @return void
  82. */
  83. Json.prototype.finalize = function() {
  84. this._writeStringified();
  85. this.end();
  86. };
  87. module.exports = Json;
  88. /**
  89. * @typedef {Object} JsonOptions
  90. * @global
  91. */