index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. function isBuffer (value) {
  2. return Buffer.isBuffer(value) || value instanceof Uint8Array
  3. }
  4. function isEncoding (encoding) {
  5. return Buffer.isEncoding(encoding)
  6. }
  7. function alloc (size, fill, encoding) {
  8. return Buffer.alloc(size, fill, encoding)
  9. }
  10. function allocUnsafe (size) {
  11. return Buffer.allocUnsafe(size)
  12. }
  13. function allocUnsafeSlow (size) {
  14. return Buffer.allocUnsafeSlow(size)
  15. }
  16. function byteLength (string, encoding) {
  17. return Buffer.byteLength(string, encoding)
  18. }
  19. function compare (a, b) {
  20. return Buffer.compare(a, b)
  21. }
  22. function concat (buffers, totalLength) {
  23. return Buffer.concat(buffers, totalLength)
  24. }
  25. function copy (source, target, targetStart, start, end) {
  26. return toBuffer(source).copy(target, targetStart, start, end)
  27. }
  28. function equals (a, b) {
  29. return toBuffer(a).equals(b)
  30. }
  31. function fill (buffer, value, offset, end, encoding) {
  32. return toBuffer(buffer).fill(value, offset, end, encoding)
  33. }
  34. function from (value, encodingOrOffset, length) {
  35. return Buffer.from(value, encodingOrOffset, length)
  36. }
  37. function includes (buffer, value, byteOffset, encoding) {
  38. return toBuffer(buffer).includes(value, byteOffset, encoding)
  39. }
  40. function indexOf (buffer, value, byfeOffset, encoding) {
  41. return toBuffer(buffer).indexOf(value, byfeOffset, encoding)
  42. }
  43. function lastIndexOf (buffer, value, byteOffset, encoding) {
  44. return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding)
  45. }
  46. function swap16 (buffer) {
  47. return toBuffer(buffer).swap16()
  48. }
  49. function swap32 (buffer) {
  50. return toBuffer(buffer).swap32()
  51. }
  52. function swap64 (buffer) {
  53. return toBuffer(buffer).swap64()
  54. }
  55. function toBuffer (buffer) {
  56. if (Buffer.isBuffer(buffer)) return buffer
  57. return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength)
  58. }
  59. function toString (buffer, encoding, start, end) {
  60. return toBuffer(buffer).toString(encoding, start, end)
  61. }
  62. function write (buffer, string, offset, length, encoding) {
  63. return toBuffer(buffer).write(string, offset, length, encoding)
  64. }
  65. function writeDoubleLE (buffer, value, offset) {
  66. return toBuffer(buffer).writeDoubleLE(value, offset)
  67. }
  68. function writeFloatLE (buffer, value, offset) {
  69. return toBuffer(buffer).writeFloatLE(value, offset)
  70. }
  71. function writeUInt32LE (buffer, value, offset) {
  72. return toBuffer(buffer).writeUInt32LE(value, offset)
  73. }
  74. function writeInt32LE (buffer, value, offset) {
  75. return toBuffer(buffer).writeInt32LE(value, offset)
  76. }
  77. function readDoubleLE (buffer, offset) {
  78. return toBuffer(buffer).readDoubleLE(offset)
  79. }
  80. function readFloatLE (buffer, offset) {
  81. return toBuffer(buffer).readFloatLE(offset)
  82. }
  83. function readUInt32LE (buffer, offset) {
  84. return toBuffer(buffer).readUInt32LE(offset)
  85. }
  86. function readInt32LE (buffer, offset) {
  87. return toBuffer(buffer).readInt32LE(offset)
  88. }
  89. module.exports = {
  90. isBuffer,
  91. isEncoding,
  92. alloc,
  93. allocUnsafe,
  94. allocUnsafeSlow,
  95. byteLength,
  96. compare,
  97. concat,
  98. copy,
  99. equals,
  100. fill,
  101. from,
  102. includes,
  103. indexOf,
  104. lastIndexOf,
  105. swap16,
  106. swap32,
  107. swap64,
  108. toBuffer,
  109. toString,
  110. write,
  111. writeDoubleLE,
  112. writeFloatLE,
  113. writeUInt32LE,
  114. writeInt32LE,
  115. readDoubleLE,
  116. readFloatLE,
  117. readUInt32LE,
  118. readInt32LE
  119. }