hypercore-streams
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -44,3 +44,3 @@ const { Writable, Readable } = require('streamx') | ||
this.index = this.start | ||
this.options = { wait: opts.wait !== false, ifAvailable: !!opts.ifAvailable } | ||
this.options = { wait: opts.wait !== false, ifAvailable: !!opts.ifAvailable, valueEncoding: opts.valueEncoding } | ||
} | ||
@@ -56,3 +56,3 @@ | ||
} | ||
if (this.tail) this.start = this.length | ||
if (this.tail) this.start = this.feed.length | ||
this.index = this.start | ||
@@ -59,0 +59,0 @@ cb(null) |
{ | ||
"name": "hypercore-streams", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "External implementation of a WriteStream and ReadStream for Hypercore", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,3 +17,4 @@ # hypercore-streams | ||
start: 0, | ||
live: true | ||
live: true, | ||
valueEncoding: 'json' | ||
}) | ||
@@ -20,0 +21,0 @@ ``` |
38
test.js
@@ -22,2 +22,24 @@ const tape = require('tape') | ||
tape('tail reading stream', function (t) { | ||
const feed = hypercore(ram) | ||
t.plan(2) | ||
feed.append(['a', 'b', 'c'], function () { | ||
const rs = new ReadStream(feed, { tail: true, live: true }) | ||
const expected = ['d', 'e'] | ||
rs.on('data', function (data) { | ||
t.same(data, Buffer.from(expected.shift())) | ||
}) | ||
feed.ready(function () { | ||
feed.append(['d', 'e']) | ||
}) | ||
rs.on('end', function () { | ||
t.fail('should not end') | ||
}) | ||
}) | ||
}) | ||
tape('live readstream', function (t) { | ||
@@ -73,1 +95,17 @@ t.plan(2) | ||
}) | ||
tape('valueEncoding test', function (t) { | ||
const feed = hypercore(ram, { valueEncoding: 'json' }) | ||
feed.append(['a', 'b', 'c'], function () { | ||
const rs = new ReadStream(feed, { valueEncoding: 'buffer' }) | ||
const expected = ['a', 'b', 'c'] | ||
rs.on('data', function (data) { | ||
t.same(data, Buffer.from('"' + expected.shift() + '"\n')) | ||
}) | ||
rs.on('end', function () { | ||
t.end() | ||
}) | ||
}) | ||
}) |
6555
150
25