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 is a Uint8Array (ArrayBufferView) for nb.buffer
// nb.buffer is the actual ArrayBuffer // 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('[packet]', nb.byteLength, 'bytes:');
console.log(JSON.stringify(packet, null, 2)); console.log(JSON.stringify(packet, null, 2));

View File

@ -46,10 +46,10 @@
var filename = path.join(dirname, name); var filename = path.join(dirname, name);
var expected = require(path.join(dirname, name.replace(/\.bin$/, '.json'))); var expected = require(path.join(dirname, name.replace(/\.bin$/, '.json')));
fs.readFile(filename, null, function (err, nb) { var nb = fs.readFileSync(filename, null);
console.log('Testing ' + filename); console.log('Testing ' + filename);
var ab = nb.buffer; var ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength);
var result; var result;
try { try {
@ -67,5 +67,4 @@
deepLike(expected, result); deepLike(expected, result);
}); });
});
}()); }());