util: reverse buffers instead of strings
This commit is contained in:
parent
6a01409b79
commit
1b868b6a9d
@ -96,31 +96,19 @@ util.time = function time(date) {
|
||||
|
||||
/**
|
||||
* Reverse a hex-string.
|
||||
* @param {String} str - Hex string.
|
||||
* @param {Buffer}
|
||||
* @returns {String} Reversed hex string.
|
||||
*/
|
||||
|
||||
util.revHex = function revHex(buf) {
|
||||
assert(Buffer.isBuffer(buf));
|
||||
|
||||
const str = buf.toString('hex');
|
||||
|
||||
let out = '';
|
||||
|
||||
for (let i = str.length - 2; i >= 0; i -= 2)
|
||||
out += str[i] + str[i + 1];
|
||||
|
||||
return out;
|
||||
return Buffer.from(buf).reverse().toString('hex');
|
||||
};
|
||||
|
||||
util.fromRev = function fromRev(str) {
|
||||
assert(typeof str === 'string');
|
||||
assert((str.length & 1) === 0);
|
||||
|
||||
let out = '';
|
||||
|
||||
for (let i = str.length - 2; i >= 0; i -= 2)
|
||||
out += str[i] + str[i + 1];
|
||||
|
||||
return Buffer.from(out, 'hex');
|
||||
return Buffer.from(str, 'hex').reverse();
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user