Skip to content

Commit ac57872

Browse files
committed
move all allocUnsafes to allocs for easier maintenance
1 parent c64c950 commit ac57872

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

index.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var NOT_QU_MASK = ~QU_MASK
1414
var name = exports.txt = exports.name = {}
1515

1616
name.encode = function (str, buf, offset) {
17-
if (!buf) buf = Buffer.allocUnsafe(name.encodingLength(str))
17+
if (!buf) buf = Buffer.alloc(name.encodingLength(str))
1818
if (!offset) offset = 0
1919
var oldOffset = offset
2020

@@ -81,7 +81,7 @@ name.encodingLength = function (n) {
8181
var string = {}
8282

8383
string.encode = function (s, buf, offset) {
84-
if (!buf) buf = Buffer.allocUnsafe(string.encodingLength(s))
84+
if (!buf) buf = Buffer.alloc(string.encodingLength(s))
8585
if (!offset) offset = 0
8686

8787
var len = buf.write(s, offset + 1)
@@ -163,7 +163,7 @@ header.encodingLength = function () {
163163
var runknown = exports.unknown = {}
164164

165165
runknown.encode = function (data, buf, offset) {
166-
if (!buf) buf = Buffer.allocUnsafe(runknown.encodingLength(data))
166+
if (!buf) buf = Buffer.alloc(runknown.encodingLength(data))
167167
if (!offset) offset = 0
168168

169169
buf.writeUInt16BE(data.length, offset)
@@ -193,7 +193,7 @@ runknown.encodingLength = function (data) {
193193
var rns = exports.ns = {}
194194

195195
rns.encode = function (data, buf, offset) {
196-
if (!buf) buf = Buffer.allocUnsafe(rns.encodingLength(data))
196+
if (!buf) buf = Buffer.alloc(rns.encodingLength(data))
197197
if (!offset) offset = 0
198198

199199
name.encode(data, buf, offset + 2)
@@ -223,7 +223,7 @@ rns.encodingLength = function (data) {
223223
var rsoa = exports.soa = {}
224224

225225
rsoa.encode = function (data, buf, offset) {
226-
if (!buf) buf = Buffer.allocUnsafe(rsoa.encodingLength(data))
226+
if (!buf) buf = Buffer.alloc(rsoa.encodingLength(data))
227227
if (!offset) offset = 0
228228

229229
var oldOffset = offset
@@ -286,11 +286,11 @@ var rtxt = exports.txt = exports.null = {}
286286
var rnull = rtxt
287287

288288
rtxt.encode = function (data, buf, offset) {
289-
if (!buf) buf = Buffer.allocUnsafe(rtxt.encodingLength(data))
289+
if (!buf) buf = Buffer.alloc(rtxt.encodingLength(data))
290290
if (!offset) offset = 0
291291

292292
if (typeof data === 'string') data = Buffer.from(data)
293-
if (!data) data = Buffer.allocUnsafe(0)
293+
if (!data) data = Buffer.alloc(0)
294294

295295
var oldOffset = offset
296296
offset += 2
@@ -330,7 +330,7 @@ rtxt.encodingLength = function (data) {
330330
var rhinfo = exports.hinfo = {}
331331

332332
rhinfo.encode = function (data, buf, offset) {
333-
if (!buf) buf = Buffer.allocUnsafe(rhinfo.encodingLength(data))
333+
if (!buf) buf = Buffer.alloc(rhinfo.encodingLength(data))
334334
if (!offset) offset = 0
335335

336336
var oldOffset = offset
@@ -372,7 +372,7 @@ var rcname = exports.cname = rptr
372372
var rdname = exports.dname = rptr
373373

374374
rptr.encode = function (data, buf, offset) {
375-
if (!buf) buf = Buffer.allocUnsafe(rptr.encodingLength(data))
375+
if (!buf) buf = Buffer.alloc(rptr.encodingLength(data))
376376
if (!offset) offset = 0
377377

378378
name.encode(data, buf, offset + 2)
@@ -400,7 +400,7 @@ rptr.encodingLength = function (data) {
400400
var rsrv = exports.srv = {}
401401

402402
rsrv.encode = function (data, buf, offset) {
403-
if (!buf) buf = Buffer.allocUnsafe(rsrv.encodingLength(data))
403+
if (!buf) buf = Buffer.alloc(rsrv.encodingLength(data))
404404
if (!offset) offset = 0
405405

406406
buf.writeUInt16BE(data.priority || 0, offset + 2)
@@ -445,7 +445,7 @@ rcaa.ISSUER_CRITICAL = 1 << 7
445445
rcaa.encode = function (data, buf, offset) {
446446
var len = rcaa.encodingLength(data)
447447

448-
if (!buf) buf = Buffer.allocUnsafe(rcaa.encodingLength(data))
448+
if (!buf) buf = Buffer.alloc(rcaa.encodingLength(data))
449449
if (!offset) offset = 0
450450

451451
if (data.issuerCritical) {
@@ -497,7 +497,7 @@ rcaa.encodingLength = function (data) {
497497
var ra = exports.a = {}
498498

499499
ra.encode = function (host, buf, offset) {
500-
if (!buf) buf = Buffer.allocUnsafe(ra.encodingLength(host))
500+
if (!buf) buf = Buffer.alloc(ra.encodingLength(host))
501501
if (!offset) offset = 0
502502

503503
buf.writeUInt16BE(4, offset)
@@ -527,7 +527,7 @@ ra.encodingLength = function () {
527527
var raaaa = exports.aaaa = {}
528528

529529
raaaa.encode = function (host, buf, offset) {
530-
if (!buf) buf = Buffer.allocUnsafe(raaaa.encodingLength(host))
530+
if (!buf) buf = Buffer.alloc(raaaa.encodingLength(host))
531531
if (!offset) offset = 0
532532

533533
buf.writeUInt16BE(16, offset)
@@ -575,7 +575,7 @@ var renc = exports.record = function (type) {
575575
var answer = exports.answer = {}
576576

577577
answer.encode = function (a, buf, offset) {
578-
if (!buf) buf = Buffer.allocUnsafe(answer.encodingLength(a))
578+
if (!buf) buf = Buffer.alloc(answer.encodingLength(a))
579579
if (!offset) offset = 0
580580

581581
var oldOffset = offset
@@ -633,7 +633,7 @@ answer.encodingLength = function (a) {
633633
var question = exports.question = {}
634634

635635
question.encode = function (q, buf, offset) {
636-
if (!buf) buf = Buffer.allocUnsafe(question.encodingLength(q))
636+
if (!buf) buf = Buffer.alloc(question.encodingLength(q))
637637
if (!offset) offset = 0
638638

639639
var oldOffset = offset
@@ -690,7 +690,7 @@ exports.CHECKING_DISABLED = 1 << 4
690690

691691
exports.encode = function (result, buf, offset) {
692692
var allocing = !buf
693-
if (allocing) buf = Buffer.allocUnsafe(exports.encodingLength(result))
693+
if (allocing) buf = Buffer.alloc(exports.encodingLength(result))
694694
if (!offset) offset = 0
695695

696696
var oldOffset = offset

0 commit comments

Comments
 (0)