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.

archive-output-stream.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * node-compress-commons
  3. *
  4. * Copyright (c) 2014 Chris Talkington, contributors.
  5. * Licensed under the MIT license.
  6. * https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
  7. */
  8. var inherits = require('util').inherits;
  9. var Transform = require('readable-stream').Transform;
  10. var ArchiveEntry = require('./archive-entry');
  11. var util = require('../util');
  12. var ArchiveOutputStream = module.exports = function(options) {
  13. if (!(this instanceof ArchiveOutputStream)) {
  14. return new ArchiveOutputStream(options);
  15. }
  16. Transform.call(this, options);
  17. this.offset = 0;
  18. this._archive = {
  19. finish: false,
  20. finished: false,
  21. processing: false
  22. };
  23. };
  24. inherits(ArchiveOutputStream, Transform);
  25. ArchiveOutputStream.prototype._appendBuffer = function(zae, source, callback) {
  26. // scaffold only
  27. };
  28. ArchiveOutputStream.prototype._appendStream = function(zae, source, callback) {
  29. // scaffold only
  30. };
  31. ArchiveOutputStream.prototype._emitErrorCallback = function(err) {
  32. if (err) {
  33. this.emit('error', err);
  34. }
  35. };
  36. ArchiveOutputStream.prototype._finish = function(ae) {
  37. // scaffold only
  38. };
  39. ArchiveOutputStream.prototype._normalizeEntry = function(ae) {
  40. // scaffold only
  41. };
  42. ArchiveOutputStream.prototype._transform = function(chunk, encoding, callback) {
  43. callback(null, chunk);
  44. };
  45. ArchiveOutputStream.prototype.entry = function(ae, source, callback) {
  46. source = source || null;
  47. if (typeof callback !== 'function') {
  48. callback = this._emitErrorCallback.bind(this);
  49. }
  50. if (!(ae instanceof ArchiveEntry)) {
  51. callback(new Error('not a valid instance of ArchiveEntry'));
  52. return;
  53. }
  54. if (this._archive.finish || this._archive.finished) {
  55. callback(new Error('unacceptable entry after finish'));
  56. return;
  57. }
  58. if (this._archive.processing) {
  59. callback(new Error('already processing an entry'));
  60. return;
  61. }
  62. this._archive.processing = true;
  63. this._normalizeEntry(ae);
  64. this._entry = ae;
  65. source = util.normalizeInputSource(source);
  66. if (Buffer.isBuffer(source)) {
  67. this._appendBuffer(ae, source, callback);
  68. } else if (util.isStream(source)) {
  69. this._appendStream(ae, source, callback);
  70. } else {
  71. this._archive.processing = false;
  72. callback(new Error('input source must be valid Stream or Buffer instance'));
  73. return;
  74. }
  75. return this;
  76. };
  77. ArchiveOutputStream.prototype.finish = function() {
  78. if (this._archive.processing) {
  79. this._archive.finish = true;
  80. return;
  81. }
  82. this._finish();
  83. };
  84. ArchiveOutputStream.prototype.getBytesWritten = function() {
  85. return this.offset;
  86. };
  87. ArchiveOutputStream.prototype.write = function(chunk, cb) {
  88. if (chunk) {
  89. this.offset += chunk.length;
  90. }
  91. return Transform.prototype.write.call(this, chunk, cb);
  92. };