Skip to content

Commit

Permalink
move all allocUnsafes to allocs for easier maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed May 26, 2021
1 parent c64c950 commit ac57872
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ac57872

Please sign in to comment.