diff --git a/bin/dns-pack.js b/bin/dns-pack.js index b1d08b1..ddb6973 100644 --- a/bin/dns-pack.js +++ b/bin/dns-pack.js @@ -3,12 +3,22 @@ // EXAMPLE: // node bin/dns-parse.js samples/a-0.mdns.bin +var path = require('path'); // pass a terminal arg var filename = process.argv[2]; +var outname = process.argv[3]; if (!filename) { - console.error("Usage: node bin/dns-pack.js "); - console.error("Example: node bin/dns-pack.js ./samples/services-0.mdns.json"); + console.error("Usage: node bin/dns-pack.js "); + console.error("Example: node bin/dns-pack.js ./samples/services-0.mdns.json ./services-0.mdns.bin"); process.exit(1); + return; +} +if (!outname) { + console.warn(''); + console.warn( + "Usage: node bin/dns-pack.js '" + filename + "' './" + path.basename(filename).replace(path.extname(filename), '') + ".bin'" + ); + console.warn(''); } @@ -32,10 +42,20 @@ fs.readFileAsync(filename, null).then(function (nb) { // nb.buffer is the actual ArrayBuffer //var ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength); - var packet = dnsjs.write(JSON.parse(buffer.toString('ascii'))); + var packet = dnsjs.write(JSON.parse(nb.toString('ascii'))); //console.log('[packet]', nb.byteLength, 'bytes:'); //console.log(JSON.stringify(packet, null, 2)); //TODO hexdump packet + var hexdump = require('hexdump.js').hexdump; + var str = hexdump(packet); + + console.log(str); + + if (outname) { + fs.writeFileSync(outname, packet, null); + console.log(''); + console.log("wrote '" + outname + "'"); + } });