Front end of the Slack clone application.

index.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 (typeof options.zlib.level === 'number' && options.zlib.level === 0) {
  35. options.store = true;
  36. }
  37. if (options.comment && options.comment.length > 0) {
  38. this.setComment(options.comment);
  39. }
  40. };
  41. inherits(ZipStream, ZipArchiveOutputStream);
  42. /**
  43. * Normalizes entry data with fallbacks for key properties.
  44. *
  45. * @private
  46. * @param {Object} data
  47. * @return {Object}
  48. */
  49. ZipStream.prototype._normalizeFileData = function(data) {
  50. data = util.defaults(data, {
  51. type: 'file',
  52. name: null,
  53. linkname: null,
  54. date: null,
  55. mode: null,
  56. store: this.options.store,
  57. comment: ''
  58. });
  59. var isDir = data.type === 'directory';
  60. var isSymlink = data.type === 'symlink';
  61. if (data.name) {
  62. data.name = util.sanitizePath(data.name);
  63. if (!isSymlink && data.name.slice(-1) === '/') {
  64. isDir = true;
  65. data.type = 'directory';
  66. } else if (isDir) {
  67. data.name += '/';
  68. }
  69. }
  70. if (isDir || isSymlink) {
  71. data.store = true;
  72. }
  73. data.date = util.dateify(data.date);
  74. return data;
  75. };
  76. /**
  77. * Appends an entry given an input source (text string, buffer, or stream).
  78. *
  79. * @param {(Buffer|Stream|String)} source The input source.
  80. * @param {Object} data
  81. * @param {String} data.name Sets the entry name including internal path.
  82. * @param {String} [data.comment] Sets the entry comment.
  83. * @param {(String|Date)} [data.date=NOW()] Sets the entry date.
  84. * @param {Number} [data.mode=D:0755/F:0644] Sets the entry permissions.
  85. * @param {Boolean} [data.store=options.store] Sets the compression method to STORE.
  86. * @param {String} [data.type=file] Sets the entry type. Defaults to `directory`
  87. * if name ends with trailing slash.
  88. * @param {Function} callback
  89. * @return this
  90. */
  91. ZipStream.prototype.entry = function(source, data, callback) {
  92. if (typeof callback !== 'function') {
  93. callback = this._emitErrorCallback.bind(this);
  94. }
  95. data = this._normalizeFileData(data);
  96. if (data.type !== 'file' && data.type !== 'directory' && data.type !== 'symlink') {
  97. callback(new Error(data.type + ' entries not currently supported'));
  98. return;
  99. }
  100. if (typeof data.name !== 'string' || data.name.length === 0) {
  101. callback(new Error('entry name must be a non-empty string value'));
  102. return;
  103. }
  104. if (data.type === 'symlink' && typeof data.linkname !== 'string') {
  105. callback(new Error('entry linkname must be a non-empty string value when type equals symlink'));
  106. return;
  107. }
  108. var entry = new ZipArchiveEntry(data.name);
  109. entry.setTime(data.date);
  110. if (data.store) {
  111. entry.setMethod(0);
  112. }
  113. if (data.comment.length > 0) {
  114. entry.setComment(data.comment);
  115. }
  116. if (data.type === 'symlink' && typeof data.mode !== 'number') {
  117. data.mode = 40960; // 0120000
  118. }
  119. if (typeof data.mode === 'number') {
  120. if (data.type === 'symlink') {
  121. data.mode |= 40960;
  122. }
  123. entry.setUnixMode(data.mode);
  124. }
  125. if (data.type === 'symlink' && typeof data.linkname === 'string') {
  126. source = new Buffer(data.linkname);
  127. }
  128. return ZipArchiveOutputStream.prototype.entry.call(this, entry, source, callback);
  129. };
  130. /**
  131. * Finalizes the instance and prevents further appending to the archive
  132. * structure (queue will continue til drained).
  133. *
  134. * @return void
  135. */
  136. ZipStream.prototype.finalize = function() {
  137. this.finish();
  138. };
  139. /**
  140. * Returns the current number of bytes written to this stream.
  141. * @function ZipStream#getBytesWritten
  142. * @returns {Number}
  143. */
  144. /**
  145. * Compress Commons ZipArchiveOutputStream
  146. * @external ZipArchiveOutputStream
  147. * @see {@link https://github.com/archiverjs/node-compress-commons}
  148. */