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 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**
  2. * ZipStream
  3. *
  4. * @ignore
  5. * @license [MIT]{@link https://github.com/archiverjs/node-zip-stream/blob/master/LICENSE}
  6. * @copyright (c) 2014 Chris Talkington, contributors.
  7. */
  8. var inherits = require('util').inherits;
  9. var ZipArchiveOutputStream = require('compress-commons').ZipArchiveOutputStream;
  10. var ZipArchiveEntry = require('compress-commons').ZipArchiveEntry;
  11. var util = require('archiver-utils');
  12. /**
  13. * @constructor
  14. * @extends external:ZipArchiveOutputStream
  15. * @param {Object} [options]
  16. * @param {String} [options.comment] Sets the zip archive comment.
  17. * @param {Boolean} [options.forceLocalTime=false] Forces the archive to contain local file times instead of UTC.
  18. * @param {Boolean} [options.forceZip64=false] Forces the archive to contain ZIP64 headers.
  19. * @param {Boolean} [options.store=false] Sets the compression method to STORE.
  20. * @param {Object} [options.zlib] Passed to [zlib]{@link https://nodejs.org/api/zlib.html#zlib_class_options}
  21. * to control compression.
  22. */
  23. var ZipStream = module.exports = function(options) {
  24. if (!(this instanceof ZipStream)) {
  25. return new ZipStream(options);
  26. }
  27. options = this.options = options || {};
  28. options.zlib = options.zlib || {};
  29. ZipArchiveOutputStream.call(this, options);
  30. if (typeof options.level === 'number' && options.level >= 0) {
  31. options.zlib.level = options.level;
  32. delete options.level;
  33. }
  34. if (!options.forceZip64 && typeof options.zlib.level === 'number' && options.zlib.level === 0) {
  35. options.store = true;
  36. }
  37. options.namePrependSlash = options.namePrependSlash || false;
  38. if (options.comment && options.comment.length > 0) {
  39. this.setComment(options.comment);
  40. }
  41. };
  42. inherits(ZipStream, ZipArchiveOutputStream);
  43. /**
  44. * Normalizes entry data with fallbacks for key properties.
  45. *
  46. * @private
  47. * @param {Object} data
  48. * @return {Object}
  49. */
  50. ZipStream.prototype._normalizeFileData = function(data) {
  51. data = util.defaults(data, {
  52. type: 'file',
  53. name: null,
  54. namePrependSlash: this.options.namePrependSlash,
  55. linkname: null,
  56. date: null,
  57. mode: null,
  58. store: this.options.store,
  59. comment: ''
  60. });
  61. var isDir = data.type === 'directory';
  62. var isSymlink = data.type === 'symlink';
  63. if (data.name) {
  64. data.name = util.sanitizePath(data.name);
  65. if (!isSymlink && data.name.slice(-1) === '/') {
  66. isDir = true;
  67. data.type = 'directory';
  68. } else if (isDir) {
  69. data.name += '/';
  70. }
  71. }
  72. if (isDir || isSymlink) {
  73. data.store = true;
  74. }
  75. data.date = util.dateify(data.date);
  76. return data;
  77. };
  78. /**
  79. * Appends an entry given an input source (text string, buffer, or stream).
  80. *
  81. * @param {(Buffer|Stream|String)} source The input source.
  82. * @param {Object} data
  83. * @param {String} data.name Sets the entry name including internal path.
  84. * @param {String} [data.comment] Sets the entry comment.
  85. * @param {(String|Date)} [data.date=NOW()] Sets the entry date.
  86. * @param {Number} [data.mode=D:0755/F:0644] Sets the entry permissions.
  87. * @param {Boolean} [data.store=options.store] Sets the compression method to STORE.
  88. * @param {String} [data.type=file] Sets the entry type. Defaults to `directory`
  89. * if name ends with trailing slash.
  90. * @param {Function} callback
  91. * @return this
  92. */
  93. ZipStream.prototype.entry = function(source, data, callback) {
  94. if (typeof callback !== 'function') {
  95. callback = this._emitErrorCallback.bind(this);
  96. }
  97. data = this._normalizeFileData(data);
  98. if (data.type !== 'file' && data.type !== 'directory' && data.type !== 'symlink') {
  99. callback(new Error(data.type + ' entries not currently supported'));
  100. return;
  101. }
  102. if (typeof data.name !== 'string' || data.name.length === 0) {
  103. callback(new Error('entry name must be a non-empty string value'));
  104. return;
  105. }
  106. if (data.type === 'symlink' && typeof data.linkname !== 'string') {
  107. callback(new Error('entry linkname must be a non-empty string value when type equals symlink'));
  108. return;
  109. }
  110. var entry = new ZipArchiveEntry(data.name);
  111. entry.setTime(data.date, this.options.forceLocalTime);
  112. if (data.namePrependSlash) {
  113. entry.setName(data.name, true);
  114. }
  115. if (data.store) {
  116. entry.setMethod(0);
  117. }
  118. if (data.comment.length > 0) {
  119. entry.setComment(data.comment);
  120. }
  121. if (data.type === 'symlink' && typeof data.mode !== 'number') {
  122. data.mode = 40960; // 0120000
  123. }
  124. if (typeof data.mode === 'number') {
  125. if (data.type === 'symlink') {
  126. data.mode |= 40960;
  127. }
  128. entry.setUnixMode(data.mode);
  129. }
  130. if (data.type === 'symlink' && typeof data.linkname === 'string') {
  131. source = Buffer.from(data.linkname);
  132. }
  133. return ZipArchiveOutputStream.prototype.entry.call(this, entry, source, callback);
  134. };
  135. /**
  136. * Finalizes the instance and prevents further appending to the archive
  137. * structure (queue will continue til drained).
  138. *
  139. * @return void
  140. */
  141. ZipStream.prototype.finalize = function() {
  142. this.finish();
  143. };
  144. /**
  145. * Returns the current number of bytes written to this stream.
  146. * @function ZipStream#getBytesWritten
  147. * @returns {Number}
  148. */
  149. /**
  150. * Compress Commons ZipArchiveOutputStream
  151. * @external ZipArchiveOutputStream
  152. * @see {@link https://github.com/archiverjs/node-compress-commons}
  153. */