index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 readDoubleBE(buffer, offset) {
  66. return toBuffer(buffer).readDoubleBE(offset)
  67. }
  68. function readDoubleLE(buffer, offset) {
  69. return toBuffer(buffer).readDoubleLE(offset)
  70. }
  71. function readFloatBE(buffer, offset) {
  72. return toBuffer(buffer).readFloatBE(offset)
  73. }
  74. function readFloatLE(buffer, offset) {
  75. return toBuffer(buffer).readFloatLE(offset)
  76. }
  77. function readInt32BE(buffer, offset) {
  78. return toBuffer(buffer).readInt32BE(offset)
  79. }
  80. function readInt32LE(buffer, offset) {
  81. return toBuffer(buffer).readInt32LE(offset)
  82. }
  83. function readUInt32BE(buffer, offset) {
  84. return toBuffer(buffer).readUInt32BE(offset)
  85. }
  86. function readUInt32LE(buffer, offset) {
  87. return toBuffer(buffer).readUInt32LE(offset)
  88. }
  89. function writeDoubleBE(buffer, value, offset) {
  90. return toBuffer(buffer).writeDoubleBE(value, offset)
  91. }
  92. function writeDoubleLE(buffer, value, offset) {
  93. return toBuffer(buffer).writeDoubleLE(value, offset)
  94. }
  95. function writeFloatBE(buffer, value, offset) {
  96. return toBuffer(buffer).writeFloatBE(value, offset)
  97. }
  98. function writeFloatLE(buffer, value, offset) {
  99. return toBuffer(buffer).writeFloatLE(value, offset)
  100. }
  101. function writeInt32BE(buffer, value, offset) {
  102. return toBuffer(buffer).writeInt32BE(value, offset)
  103. }
  104. function writeInt32LE(buffer, value, offset) {
  105. return toBuffer(buffer).writeInt32LE(value, offset)
  106. }
  107. function writeUInt32BE(buffer, value, offset) {
  108. return toBuffer(buffer).writeUInt32BE(value, offset)
  109. }
  110. function writeUInt32LE(buffer, value, offset) {
  111. return toBuffer(buffer).writeUInt32LE(value, offset)
  112. }
  113. module.exports = {
  114. isBuffer,
  115. isEncoding,
  116. alloc,
  117. allocUnsafe,
  118. allocUnsafeSlow,
  119. byteLength,
  120. compare,
  121. concat,
  122. copy,
  123. equals,
  124. fill,
  125. from,
  126. includes,
  127. indexOf,
  128. lastIndexOf,
  129. swap16,
  130. swap32,
  131. swap64,
  132. toBuffer,
  133. toString,
  134. write,
  135. readDoubleBE,
  136. readDoubleLE,
  137. readFloatBE,
  138. readFloatLE,
  139. readInt32BE,
  140. readInt32LE,
  141. readUInt32BE,
  142. readUInt32LE,
  143. writeDoubleBE,
  144. writeDoubleLE,
  145. writeFloatBE,
  146. writeFloatLE,
  147. writeInt32BE,
  148. writeInt32LE,
  149. writeUInt32BE,
  150. writeUInt32LE
  151. }