dns-suite.js/test/packer.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-02-03 04:19:59 +00:00
;(function () {
'use strict';
2017-02-11 22:41:01 +00:00
var fs = require('fs');
var path = require('path');
var dnsjs = require('../').DNSPacket;
var dirname = path.join(__dirname, 'fixtures');
var expected; // shim
var onefile = process.argv[2];
var json = JSON.parse(fs.readFileSync(onefile, 'utf8'));
var ab = dnsjs.write(json);
//console.log(ab);
var ui8 = new Uint8Array(ab);
//console.log(ui8);
var bytecount = 0;
var str = [].slice.call(ui8).map(function (i) {
var h = i.toString(16);
if (h.length < 2) {
h = '0' + h;
}
return h;
}).join('').match(/.{1,2}/g).join(' ').match(/.{1,47}/g).map(function (str) {
var lead = bytecount.toString(16);
bytecount += 10;
while (lead.length < 8) {
lead = '0' + lead;
}
return lead + ' ' + str;
}).join('\n');
var trail = ab.byteLength.toString(16);
while (trail.length < 8) {
trail = '0' + trail;
}
console.log('');
console.log('DEBUG with hexdump: ');
console.log('hexdump ' + onefile.replace(/\.[^\.]*$/, '.bin'));
console.log('');
console.log(str + '\n' + trail);
console.log('');
2017-02-03 04:19:59 +00:00
}());