hypercore-byte-stream
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -142,3 +142,6 @@ const assert = require('assert') | ||
if (this._ended) return this.push(null) | ||
if (this._range.length === 0) return this.push(null) | ||
if (this._range.length === 0) { | ||
this._cleanup() | ||
return this.push(null) | ||
} | ||
@@ -150,2 +153,3 @@ if (!this._opened) { | ||
if ((this._range.end !== -1 && this._range.start >= this._range.end) || this._range.length === 0) { | ||
this._cleanup() | ||
return this.push(null) | ||
@@ -152,0 +156,0 @@ } |
{ | ||
"name": "hypercore-byte-stream", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "A Readable stream wrapper around Hypercore that supports reading byte ranges.", | ||
@@ -25,3 +25,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"hypercore": "^6.24.0", | ||
"hypercore": "^9.1.0", | ||
"random-access-memory": "^3.1.1", | ||
@@ -28,0 +28,0 @@ "tape": "^4.9.2" |
@@ -36,4 +36,4 @@ const ram = require('random-access-memory') | ||
let s1 = core1.replicate({ live: true }) | ||
s1.pipe(core2.replicate({ live: true })).pipe(s1) | ||
let s1 = core1.replicate(true, { live: true }) | ||
s1.pipe(core2.replicate(false, { live: true })).pipe(s1) | ||
@@ -40,0 +40,0 @@ let stream = createStream() |
@@ -251,2 +251,60 @@ const test = require('tape') | ||
}) | ||
test(`${tag}: _destroy is always called with empty ranges`, t => { | ||
create(10, 100, (err, input, output, stream, records) => { | ||
t.error(err, 'create stream ok') | ||
stream.start({ | ||
feed: output, | ||
byteOffset: 101, | ||
byteLength: 99 | ||
}) | ||
stream.on('data', () => {}) | ||
stream.on('error', err => { | ||
t.error(err) | ||
}) | ||
const expectedSelections = output.sparse ? 0 : 1 | ||
stream.on('end', () => { | ||
t.true(stream._ended) | ||
t.false(stream._range) | ||
t.same(output._selections.length, expectedSelections) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
test(`${tag}: _destroy always called for various ranges`, t => { | ||
t.plan(3 * 7) | ||
const byteRanges = [ | ||
[0, 0], | ||
[0, 10], | ||
[101, 150], | ||
[900, -1], | ||
[200, 300], | ||
[350, 450], | ||
[450, 750] | ||
] | ||
for (const [byteStart, byteEnd] of byteRanges) { | ||
testDestroy(byteStart, byteEnd) | ||
} | ||
function testDestroy (byteStart, byteEnd) { | ||
create(10, 100, (err, input, output, stream, records) => { | ||
stream.start({ | ||
feed: output, | ||
byteOffset: 101, | ||
byteLength: 99 | ||
}) | ||
stream.on('data', () => {}) | ||
stream.on('error', err => { | ||
t.error(err) | ||
}) | ||
const expectedSelections = output.sparse ? 0 : 1 | ||
stream.on('end', () => { | ||
t.true(stream._ended) | ||
t.false(stream._range) | ||
t.same(output._selections.length, expectedSelections) | ||
}) | ||
}) | ||
} | ||
}) | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17565
458