diff --git a/bin/dns-parse.js b/bin/dns-parse.js index 298af41..b5d6023 100644 --- a/bin/dns-parse.js +++ b/bin/dns-parse.js @@ -31,7 +31,8 @@ fs.readFileAsync(filename, null).then(function (nb) { // nb is a Uint8Array (ArrayBufferView) for nb.buffer // nb.buffer is the actual ArrayBuffer - var packet = dnsjs.parse(nb.buffer); + var ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength); + var packet = dnsjs.parse(ab); console.log('[packet]', nb.byteLength, 'bytes:'); console.log(JSON.stringify(packet, null, 2)); diff --git a/test/parser.js b/test/parser.js index 768550e..d7b3273 100644 --- a/test/parser.js +++ b/test/parser.js @@ -46,26 +46,25 @@ var filename = path.join(dirname, name); var expected = require(path.join(dirname, name.replace(/\.bin$/, '.json'))); - fs.readFile(filename, null, function (err, nb) { - console.log('Testing ' + filename); + var nb = fs.readFileSync(filename, null); + console.log('Testing ' + filename); - var ab = nb.buffer; - var result; + var ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength); + var result; - try { - result = dnsjs.parse(ab); - } catch(e) { - console.log(ab); - console.error('[Error] ' + e.message); - console.error(''); - //console.error(e.stack); - return; - } + try { + result = dnsjs.parse(ab); + } catch(e) { + console.log(ab); + console.error('[Error] ' + e.message); + console.error(''); + //console.error(e.stack); + return; + } - // TODO deepHas - // compare two objects and make sure that the second has all of what the first has (but perhaps more) + // TODO deepHas + // compare two objects and make sure that the second has all of what the first has (but perhaps more) - deepLike(expected, result); - }); + deepLike(expected, result); }); }());