149 lines
3.1 KiB
JavaScript
149 lines
3.1 KiB
JavaScript
function isBuffer (value) {
|
|
return Buffer.isBuffer(value) || value instanceof Uint8Array
|
|
}
|
|
|
|
function isEncoding (encoding) {
|
|
return Buffer.isEncoding(encoding)
|
|
}
|
|
|
|
function alloc (size, fill, encoding) {
|
|
return Buffer.alloc(size, fill, encoding)
|
|
}
|
|
|
|
function allocUnsafe (size) {
|
|
return Buffer.allocUnsafe(size)
|
|
}
|
|
|
|
function allocUnsafeSlow (size) {
|
|
return Buffer.allocUnsafeSlow(size)
|
|
}
|
|
|
|
function byteLength (string, encoding) {
|
|
return Buffer.byteLength(string, encoding)
|
|
}
|
|
|
|
function compare (a, b) {
|
|
return Buffer.compare(a, b)
|
|
}
|
|
|
|
function concat (buffers, totalLength) {
|
|
return Buffer.concat(buffers, totalLength)
|
|
}
|
|
|
|
function copy (source, target, targetStart, start, end) {
|
|
return toBuffer(source).copy(target, targetStart, start, end)
|
|
}
|
|
|
|
function equals (a, b) {
|
|
return toBuffer(a).equals(b)
|
|
}
|
|
|
|
function fill (buffer, value, offset, end, encoding) {
|
|
return toBuffer(buffer).fill(value, offset, end, encoding)
|
|
}
|
|
|
|
function from (value, encodingOrOffset, length) {
|
|
return Buffer.from(value, encodingOrOffset, length)
|
|
}
|
|
|
|
function includes (buffer, value, byteOffset, encoding) {
|
|
return toBuffer(buffer).includes(value, byteOffset, encoding)
|
|
}
|
|
|
|
function indexOf (buffer, value, byfeOffset, encoding) {
|
|
return toBuffer(buffer).indexOf(value, byfeOffset, encoding)
|
|
}
|
|
|
|
function lastIndexOf (buffer, value, byteOffset, encoding) {
|
|
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding)
|
|
}
|
|
|
|
function swap16 (buffer) {
|
|
return toBuffer(buffer).swap16()
|
|
}
|
|
|
|
function swap32 (buffer) {
|
|
return toBuffer(buffer).swap32()
|
|
}
|
|
|
|
function swap64 (buffer) {
|
|
return toBuffer(buffer).swap64()
|
|
}
|
|
|
|
function toBuffer (buffer) {
|
|
if (Buffer.isBuffer(buffer)) return buffer
|
|
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
}
|
|
|
|
function toString (buffer, encoding, start, end) {
|
|
return toBuffer(buffer).toString(encoding, start, end)
|
|
}
|
|
|
|
function write (buffer, string, offset, length, encoding) {
|
|
return toBuffer(buffer).write(string, offset, length, encoding)
|
|
}
|
|
|
|
function writeDoubleLE (buffer, value, offset) {
|
|
return toBuffer(buffer).writeDoubleLE(value, offset)
|
|
}
|
|
|
|
function writeFloatLE (buffer, value, offset) {
|
|
return toBuffer(buffer).writeFloatLE(value, offset)
|
|
}
|
|
|
|
function writeUInt32LE (buffer, value, offset) {
|
|
return toBuffer(buffer).writeUInt32LE(value, offset)
|
|
}
|
|
|
|
function writeInt32LE (buffer, value, offset) {
|
|
return toBuffer(buffer).writeInt32LE(value, offset)
|
|
}
|
|
|
|
function readDoubleLE (buffer, offset) {
|
|
return toBuffer(buffer).readDoubleLE(offset)
|
|
}
|
|
|
|
function readFloatLE (buffer, offset) {
|
|
return toBuffer(buffer).readFloatLE(offset)
|
|
}
|
|
|
|
function readUInt32LE (buffer, offset) {
|
|
return toBuffer(buffer).readUInt32LE(offset)
|
|
}
|
|
|
|
function readInt32LE (buffer, offset) {
|
|
return toBuffer(buffer).readInt32LE(offset)
|
|
}
|
|
|
|
module.exports = {
|
|
isBuffer,
|
|
isEncoding,
|
|
alloc,
|
|
allocUnsafe,
|
|
allocUnsafeSlow,
|
|
byteLength,
|
|
compare,
|
|
concat,
|
|
copy,
|
|
equals,
|
|
fill,
|
|
from,
|
|
includes,
|
|
indexOf,
|
|
lastIndexOf,
|
|
swap16,
|
|
swap32,
|
|
swap64,
|
|
toBuffer,
|
|
toString,
|
|
write,
|
|
writeDoubleLE,
|
|
writeFloatLE,
|
|
writeUInt32LE,
|
|
writeInt32LE,
|
|
readDoubleLE,
|
|
readFloatLE,
|
|
readUInt32LE,
|
|
readInt32LE
|
|
}
|