create proper ArrayBuffer from NodeBuffer https://github.com/nodejs/node/issues/11132

This commit is contained in:
AJ ONeal 2017-02-06 10:53:07 -07:00
parent ffac12f700
commit 8711c0b16e
2 changed files with 18 additions and 18 deletions

View File

@ -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));

View File

@ -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);
});
}());