bytesToUuid.js 699 B

1234567891011121314151617181920212223
  1. /**
  2. * Convert array of 16 byte values to UUID string format of the form:
  3. * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  4. */
  5. var byteToHex = [];
  6. for (var i = 0; i < 256; ++i) {
  7. byteToHex[i] = (i + 0x100).toString(16).substr(1);
  8. }
  9. function bytesToUuid(buf, offset) {
  10. var i = offset || 0;
  11. var bth = byteToHex;
  12. return bth[buf[i++]] + bth[buf[i++]] +
  13. bth[buf[i++]] + bth[buf[i++]] + '-' +
  14. bth[buf[i++]] + bth[buf[i++]] + '-' +
  15. bth[buf[i++]] + bth[buf[i++]] + '-' +
  16. bth[buf[i++]] + bth[buf[i++]] + '-' +
  17. bth[buf[i++]] + bth[buf[i++]] +
  18. bth[buf[i++]] + bth[buf[i++]] +
  19. bth[buf[i++]] + bth[buf[i++]];
  20. }
  21. module.exports = bytesToUuid;