v16.js 1.2 KB

1234567891011121314151617181920212223242526
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const tslib_1 = require("tslib");
  4. const decodeAscii_1 = require("../decodeAscii");
  5. const v18_1 = tslib_1.__importDefault(require("./v18"));
  6. const hasBuffer = typeof Buffer !== 'undefined';
  7. const utf8Slice = hasBuffer ? Buffer.prototype.utf8Slice : null;
  8. const from = hasBuffer ? Buffer.from : null;
  9. const shortDecoder = (buf, start, length) => (0, decodeAscii_1.decodeAsciiMax15)(buf, start, length) ?? (0, v18_1.default)(buf, start, length);
  10. const midDecoder = (buf, start, length) => (0, decodeAscii_1.decodeAscii)(buf, start, length) ?? (0, v18_1.default)(buf, start, length);
  11. const longDecoder = utf8Slice
  12. ? (buf, start, length) => utf8Slice.call(buf, start, start + length)
  13. : from
  14. ? (buf, start, length) => from(buf)
  15. .subarray(start, start + length)
  16. .toString('utf8')
  17. : v18_1.default;
  18. const decoder = (buf, start, length) => {
  19. if (length < 16)
  20. return shortDecoder(buf, start, length);
  21. if (length < 32)
  22. return midDecoder(buf, start, length);
  23. return longDecoder(buf, start, length);
  24. };
  25. exports.default = decoder;
  26. //# sourceMappingURL=v16.js.map