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.

util.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 util = module.exports = {};
  9. util.dateToDos = function(d, forceLocalTime) {
  10. forceLocalTime = forceLocalTime || false;
  11. var year = forceLocalTime ? d.getFullYear() : d.getUTCFullYear();
  12. if (year < 1980) {
  13. return 2162688; // 1980-1-1 00:00:00
  14. } else if (year >= 2044) {
  15. return 2141175677; // 2043-12-31 23:59:58
  16. }
  17. var val = {
  18. year: year,
  19. month: forceLocalTime ? d.getMonth() : d.getUTCMonth(),
  20. date: forceLocalTime ? d.getDate() : d.getUTCDate(),
  21. hours: forceLocalTime ? d.getHours() : d.getUTCHours(),
  22. minutes: forceLocalTime ? d.getMinutes() : d.getUTCMinutes(),
  23. seconds: forceLocalTime ? d.getSeconds() : d.getUTCSeconds()
  24. };
  25. return ((val.year - 1980) << 25) | ((val.month + 1) << 21) | (val.date << 16) |
  26. (val.hours << 11) | (val.minutes << 5) | (val.seconds / 2);
  27. };
  28. util.dosToDate = function(dos) {
  29. return new Date(((dos >> 25) & 0x7f) + 1980, ((dos >> 21) & 0x0f) - 1, (dos >> 16) & 0x1f, (dos >> 11) & 0x1f, (dos >> 5) & 0x3f, (dos & 0x1f) << 1);
  30. };
  31. util.fromDosTime = function(buf) {
  32. return util.dosToDate(buf.readUInt32LE(0));
  33. };
  34. util.getEightBytes = function(v) {
  35. var buf = Buffer.alloc(8);
  36. buf.writeUInt32LE(v % 0x0100000000, 0);
  37. buf.writeUInt32LE((v / 0x0100000000) | 0, 4);
  38. return buf;
  39. };
  40. util.getShortBytes = function(v) {
  41. var buf = Buffer.alloc(2);
  42. buf.writeUInt16LE((v & 0xFFFF) >>> 0, 0);
  43. return buf;
  44. };
  45. util.getShortBytesValue = function(buf, offset) {
  46. return buf.readUInt16LE(offset);
  47. };
  48. util.getLongBytes = function(v) {
  49. var buf = Buffer.alloc(4);
  50. buf.writeUInt32LE((v & 0xFFFFFFFF) >>> 0, 0);
  51. return buf;
  52. };
  53. util.getLongBytesValue = function(buf, offset) {
  54. return buf.readUInt32LE(offset);
  55. };
  56. util.toDosTime = function(d) {
  57. return util.getLongBytes(util.dateToDos(d));
  58. };