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.

general-purpose-bit.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 zipUtil = require('./util');
  9. var DATA_DESCRIPTOR_FLAG = 1 << 3;
  10. var ENCRYPTION_FLAG = 1 << 0;
  11. var NUMBER_OF_SHANNON_FANO_TREES_FLAG = 1 << 2;
  12. var SLIDING_DICTIONARY_SIZE_FLAG = 1 << 1;
  13. var STRONG_ENCRYPTION_FLAG = 1 << 6;
  14. var UFT8_NAMES_FLAG = 1 << 11;
  15. var GeneralPurposeBit = module.exports = function() {
  16. if (!(this instanceof GeneralPurposeBit)) {
  17. return new GeneralPurposeBit();
  18. }
  19. this.descriptor = false;
  20. this.encryption = false;
  21. this.utf8 = false;
  22. this.numberOfShannonFanoTrees = 0;
  23. this.strongEncryption = false;
  24. this.slidingDictionarySize = 0;
  25. return this;
  26. };
  27. GeneralPurposeBit.prototype.encode = function() {
  28. return zipUtil.getShortBytes(
  29. (this.descriptor ? DATA_DESCRIPTOR_FLAG : 0) |
  30. (this.utf8 ? UFT8_NAMES_FLAG : 0) |
  31. (this.encryption ? ENCRYPTION_FLAG : 0) |
  32. (this.strongEncryption ? STRONG_ENCRYPTION_FLAG : 0)
  33. );
  34. };
  35. GeneralPurposeBit.prototype.parse = function(buf, offset) {
  36. var flag = zipUtil.getShortBytesValue(buf, offset);
  37. var gbp = new GeneralPurposeBit();
  38. gbp.useDataDescriptor((flag & DATA_DESCRIPTOR_FLAG) !== 0);
  39. gbp.useUTF8ForNames((flag & UFT8_NAMES_FLAG) !== 0);
  40. gbp.useStrongEncryption((flag & STRONG_ENCRYPTION_FLAG) !== 0);
  41. gbp.useEncryption((flag & ENCRYPTION_FLAG) !== 0);
  42. gbp.setSlidingDictionarySize((flag & SLIDING_DICTIONARY_SIZE_FLAG) !== 0 ? 8192 : 4096);
  43. gbp.setNumberOfShannonFanoTrees((flag & NUMBER_OF_SHANNON_FANO_TREES_FLAG) !== 0 ? 3 : 2);
  44. return gbp;
  45. };
  46. GeneralPurposeBit.prototype.setNumberOfShannonFanoTrees = function(n) {
  47. this.numberOfShannonFanoTrees = n;
  48. };
  49. GeneralPurposeBit.prototype.getNumberOfShannonFanoTrees = function() {
  50. return this.numberOfShannonFanoTrees;
  51. };
  52. GeneralPurposeBit.prototype.setSlidingDictionarySize = function(n) {
  53. this.slidingDictionarySize = n;
  54. };
  55. GeneralPurposeBit.prototype.getSlidingDictionarySize = function() {
  56. return this.slidingDictionarySize;
  57. };
  58. GeneralPurposeBit.prototype.useDataDescriptor = function(b) {
  59. this.descriptor = b;
  60. };
  61. GeneralPurposeBit.prototype.usesDataDescriptor = function() {
  62. return this.descriptor;
  63. };
  64. GeneralPurposeBit.prototype.useEncryption = function(b) {
  65. this.encryption = b;
  66. };
  67. GeneralPurposeBit.prototype.usesEncryption = function() {
  68. return this.encryption;
  69. };
  70. GeneralPurposeBit.prototype.useStrongEncryption = function(b) {
  71. this.strongEncryption = b;
  72. };
  73. GeneralPurposeBit.prototype.usesStrongEncryption = function() {
  74. return this.strongEncryption;
  75. };
  76. GeneralPurposeBit.prototype.useUTF8ForNames = function(b) {
  77. this.utf8 = b;
  78. };
  79. GeneralPurposeBit.prototype.usesUTF8ForNames = function() {
  80. return this.utf8;
  81. };