compatibility fix: return NodeBuffer from DNSPacket.write

This commit is contained in:
AJ ONeal 2017-02-23 16:35:19 -07:00
parent 3049b40031
commit 2062e359ae
3 changed files with 21 additions and 9 deletions

View File

@ -51,8 +51,19 @@ Similar API to `dns.js` and `native-dns-packet`.
Install Install
------- -------
You can use git to install v1.x (and get updates) or just v1.0.x (and only get patches).
The API will not break until v2.
```bash ```bash
npm install git+https://git@git.daplie.com:Daplie/dns-suite # latest of v1.x
npm install 'git+https://git@git.daplie.com:Daplie/dns-suite#v1'
```
Don't have git? You can bow down to the gods of the centralized, monopolized, concentrated, dictatornet
(as we like to call it here at Daplie Labs):
```
npm install --save dns-suite
``` ```
**Test**: **Test**:

13
dns.js
View File

@ -1,13 +1,10 @@
;(function (exports) { ;(function (exports) {
'use strict'; 'use strict';
// Value: IP Address
// Meaning:Use: 16 octets represting the IP address
var Parser = (exports.DNS_PARSER || require('./dns.parser.js').DNS_PARSER); var Parser = (exports.DNS_PARSER || require('./dns.parser.js').DNS_PARSER);
var Packer = (exports.DNS_PACKER || require('./dns.packer.js').DNS_PACKER); var Packer = (exports.DNS_PACKER || require('./dns.packer.js').DNS_PACKER);
var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES; //var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES;
var types = exports.DNS_TYPES || require('./dns.types.js').DNS_TYPES; //var types = exports.DNS_TYPES || require('./dns.types.js').DNS_TYPES;
exports.DNSPacket = { exports.DNSPacket = {
parse: function (nb) { parse: function (nb) {
// backwards compat with node buffer // backwards compat with node buffer
@ -15,7 +12,7 @@ exports.DNSPacket = {
var packet = Parser.unpack(ab); var packet = Parser.unpack(ab);
function tryParseRdata(record) { function tryParseRdata(record) {
try { try {
record = Parser.unpackRdata(ab, packet, record); record = Parser.unpackRdata(ab, packet, record);
@ -31,7 +28,11 @@ exports.DNSPacket = {
return packet; return packet;
} }
// Backwards compat
, write: function (json) { , write: function (json) {
return Buffer.from(Packer.pack(json));
}
, pack: function (json) {
return Packer.pack(json); return Packer.pack(json);
} }
}; };

View File

@ -2,7 +2,7 @@
'use strict'; 'use strict';
var fs = require('fs'); var fs = require('fs');
var path = require('path'); //var path = require('path');
var dnsjs = require('../').DNSPacket; var dnsjs = require('../').DNSPacket;
//var dirname = path.join(__dirname, 'fixtures'); //var dirname = path.join(__dirname, 'fixtures');
@ -21,7 +21,7 @@
var json = JSON.parse(fs.readFileSync(onefile, 'utf8')); var json = JSON.parse(fs.readFileSync(onefile, 'utf8'));
var ab = dnsjs.write(json); var ab = dnsjs.write(json).buffer;
//console.log(ab); //console.log(ab);
//console.log(ui8); //console.log(ui8);