From ac578722f2707310b841b65aae61d6332f8882a1 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Wed, 26 May 2021 11:28:14 +0200 Subject: [PATCH] move all allocUnsafes to allocs for easier maintenance --- index.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 77da2ab..fa850ca 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ var NOT_QU_MASK = ~QU_MASK var name = exports.txt = exports.name = {} name.encode = function (str, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(name.encodingLength(str)) + if (!buf) buf = Buffer.alloc(name.encodingLength(str)) if (!offset) offset = 0 var oldOffset = offset @@ -81,7 +81,7 @@ name.encodingLength = function (n) { var string = {} string.encode = function (s, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(string.encodingLength(s)) + if (!buf) buf = Buffer.alloc(string.encodingLength(s)) if (!offset) offset = 0 var len = buf.write(s, offset + 1) @@ -163,7 +163,7 @@ header.encodingLength = function () { var runknown = exports.unknown = {} runknown.encode = function (data, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(runknown.encodingLength(data)) + if (!buf) buf = Buffer.alloc(runknown.encodingLength(data)) if (!offset) offset = 0 buf.writeUInt16BE(data.length, offset) @@ -193,7 +193,7 @@ runknown.encodingLength = function (data) { var rns = exports.ns = {} rns.encode = function (data, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(rns.encodingLength(data)) + if (!buf) buf = Buffer.alloc(rns.encodingLength(data)) if (!offset) offset = 0 name.encode(data, buf, offset + 2) @@ -223,7 +223,7 @@ rns.encodingLength = function (data) { var rsoa = exports.soa = {} rsoa.encode = function (data, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(rsoa.encodingLength(data)) + if (!buf) buf = Buffer.alloc(rsoa.encodingLength(data)) if (!offset) offset = 0 var oldOffset = offset @@ -286,11 +286,11 @@ var rtxt = exports.txt = exports.null = {} var rnull = rtxt rtxt.encode = function (data, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(rtxt.encodingLength(data)) + if (!buf) buf = Buffer.alloc(rtxt.encodingLength(data)) if (!offset) offset = 0 if (typeof data === 'string') data = Buffer.from(data) - if (!data) data = Buffer.allocUnsafe(0) + if (!data) data = Buffer.alloc(0) var oldOffset = offset offset += 2 @@ -330,7 +330,7 @@ rtxt.encodingLength = function (data) { var rhinfo = exports.hinfo = {} rhinfo.encode = function (data, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(rhinfo.encodingLength(data)) + if (!buf) buf = Buffer.alloc(rhinfo.encodingLength(data)) if (!offset) offset = 0 var oldOffset = offset @@ -372,7 +372,7 @@ var rcname = exports.cname = rptr var rdname = exports.dname = rptr rptr.encode = function (data, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(rptr.encodingLength(data)) + if (!buf) buf = Buffer.alloc(rptr.encodingLength(data)) if (!offset) offset = 0 name.encode(data, buf, offset + 2) @@ -400,7 +400,7 @@ rptr.encodingLength = function (data) { var rsrv = exports.srv = {} rsrv.encode = function (data, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(rsrv.encodingLength(data)) + if (!buf) buf = Buffer.alloc(rsrv.encodingLength(data)) if (!offset) offset = 0 buf.writeUInt16BE(data.priority || 0, offset + 2) @@ -445,7 +445,7 @@ rcaa.ISSUER_CRITICAL = 1 << 7 rcaa.encode = function (data, buf, offset) { var len = rcaa.encodingLength(data) - if (!buf) buf = Buffer.allocUnsafe(rcaa.encodingLength(data)) + if (!buf) buf = Buffer.alloc(rcaa.encodingLength(data)) if (!offset) offset = 0 if (data.issuerCritical) { @@ -497,7 +497,7 @@ rcaa.encodingLength = function (data) { var ra = exports.a = {} ra.encode = function (host, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(ra.encodingLength(host)) + if (!buf) buf = Buffer.alloc(ra.encodingLength(host)) if (!offset) offset = 0 buf.writeUInt16BE(4, offset) @@ -527,7 +527,7 @@ ra.encodingLength = function () { var raaaa = exports.aaaa = {} raaaa.encode = function (host, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(raaaa.encodingLength(host)) + if (!buf) buf = Buffer.alloc(raaaa.encodingLength(host)) if (!offset) offset = 0 buf.writeUInt16BE(16, offset) @@ -575,7 +575,7 @@ var renc = exports.record = function (type) { var answer = exports.answer = {} answer.encode = function (a, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(answer.encodingLength(a)) + if (!buf) buf = Buffer.alloc(answer.encodingLength(a)) if (!offset) offset = 0 var oldOffset = offset @@ -633,7 +633,7 @@ answer.encodingLength = function (a) { var question = exports.question = {} question.encode = function (q, buf, offset) { - if (!buf) buf = Buffer.allocUnsafe(question.encodingLength(q)) + if (!buf) buf = Buffer.alloc(question.encodingLength(q)) if (!offset) offset = 0 var oldOffset = offset @@ -690,7 +690,7 @@ exports.CHECKING_DISABLED = 1 << 4 exports.encode = function (result, buf, offset) { var allocing = !buf - if (allocing) buf = Buffer.allocUnsafe(exports.encodingLength(result)) + if (allocing) buf = Buffer.alloc(exports.encodingLength(result)) if (!offset) offset = 0 var oldOffset = offset