Current Folder
This commit is contained in:
1 parent
8b3382289b
commit
cfcada880d
4379 files changed
No files matched your search
-34
@@ -1,34 +0,0 @@
|
||||
'use strict'
|
||||
const varint = require('varint')
|
||||
|
||||
module.exports = {
|
||||
numberToBuffer,
|
||||
bufferToNumber,
|
||||
varintBufferEncode,
|
||||
varintBufferDecode,
|
||||
varintEncode
|
||||
}
|
||||
|
||||
function bufferToNumber (buf) {
|
||||
return parseInt(buf.toString('hex'), 16)
|
||||
}
|
||||
|
||||
function numberToBuffer (num) {
|
||||
let hexString = num.toString(16)
|
||||
if (hexString.length % 2 === 1) {
|
||||
hexString = '0' + hexString
|
||||
}
|
||||
return Buffer.from(hexString, 'hex')
|
||||
}
|
||||
|
||||
function varintBufferEncode (input) {
|
||||
return Buffer.from(varint.encode(bufferToNumber(input)))
|
||||
}
|
||||
|
||||
function varintBufferDecode (input) {
|
||||
return numberToBuffer(varint.decode(input))
|
||||
}
|
||||
|
||||
function varintEncode (num) {
|
||||
return Buffer.from(varint.encode(num))
|
||||
}
|
||||
Reference in new issue
Block a user