create proper ArrayBuffer from NodeBuffer https://github.com/nodejs/node/issues/11132
This commit is contained in:
parent
ffac12f700
commit
8711c0b16e
|
@ -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));
|
||||||
|
|
|
@ -46,26 +46,25 @@
|
||||||
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 {
|
||||||
result = dnsjs.parse(ab);
|
result = dnsjs.parse(ab);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(ab);
|
console.log(ab);
|
||||||
console.error('[Error] ' + e.message);
|
console.error('[Error] ' + e.message);
|
||||||
console.error('');
|
console.error('');
|
||||||
//console.error(e.stack);
|
//console.error(e.stack);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO deepHas
|
// TODO deepHas
|
||||||
// compare two objects and make sure that the second has all of what the first has (but perhaps more)
|
// 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);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
Loading…
Reference in New Issue