hypercore-protocol
Advanced tools
Comparing version 4.3.2 to 4.4.0
@@ -210,2 +210,7 @@ var events = require('events') | ||
Protocol.parseDiscoveryKey = function (buf) { | ||
if (buf[0] !== 0) throw Error('Invalid message') | ||
return messages.Open.decode(buf, 1).feed | ||
} | ||
Protocol.prototype.finalize = function () { | ||
@@ -212,0 +217,0 @@ this._encode.push(null) |
{ | ||
"name": "hypercore-protocol", | ||
"version": "4.3.2", | ||
"version": "4.4.0", | ||
"description": "Stream that implements the hypercore protocol", | ||
@@ -23,2 +23,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"length-prefixed-message": "^3.0.3", | ||
"standard": "^7.1.0", | ||
@@ -25,0 +26,0 @@ "tape": "^4.5.1" |
@@ -31,2 +31,6 @@ # hypercore-protocol | ||
#### `var k = protocol.parseDiscoveryKey(buf)` | ||
Parse the discovery key encoded in `buf` which is the first varint message taken from a hypercore feed stream. | ||
#### `var p = protocol([options], [onopen])` | ||
@@ -33,0 +37,0 @@ |
12
test.js
var tape = require('tape') | ||
var protocol = require('./') | ||
var lpm = require('length-prefixed-message') | ||
@@ -7,2 +8,13 @@ var key = Buffer('12345678123456781234567812345678') | ||
tape('parse discovery key', function (t) { | ||
t.plan(1) | ||
var stream = protocol() | ||
var channel = stream.open(key) | ||
lpm.read(stream, function (buf) { | ||
var parsed = protocol.parseDiscoveryKey(buf) | ||
t.deepEqual(parsed, channel.discoveryKey) | ||
}) | ||
}) | ||
tape('open channel', function (t) { | ||
@@ -9,0 +21,0 @@ t.plan(3) |
31099
720
187
3