hypercore-byte-stream
Advanced tools
Comparing version 1.0.3 to 1.0.4
18
index.js
@@ -35,3 +35,4 @@ const assert = require('assert') | ||
assert(!blockLength || blockLength >= 0, 'end must be >= 0') | ||
assert(!byteLength || byteLength >= 0, 'length must be a >= 0 or -1') | ||
assert(!byteLength || byteLength >= -1, 'length must be a >= 0 or -1') | ||
assert((byteLength !== -1 && byteOffset !== -1) || byteLength === -1, 'byteLength requires byteOffset') | ||
@@ -41,5 +42,5 @@ this.feed = feed | ||
start: blockOffset || 0, | ||
end: (blockOffset && (blockLength !== undefined)) ? blockOffset + blockLength : -1, | ||
end: ((blockOffset !== undefined) && (blockLength !== undefined)) ? blockOffset + blockLength : -1, | ||
byteOffset: byteOffset || 0, | ||
length: (byteLength !== undefined) ? byteLength : -1 | ||
length: blockLength === 0 ? 0 : (byteLength !== undefined) ? byteLength : -1 | ||
} | ||
@@ -60,6 +61,7 @@ | ||
this.open = true | ||
if (this._range.byteOffset === -1) return onstart(null, this._range.start, 0) | ||
this.feed.seek(this._range.byteOffset, this._range, onstart) | ||
}) | ||
function onend (err, index) { | ||
function onend (err, index, offset) { | ||
if (err || !self._range) return | ||
@@ -73,7 +75,7 @@ if (self._ended || self.destroyed) return | ||
start: self._range.start, | ||
end: index, | ||
end: offset ? index + 1 : index, // if offset === 0 we should stop just before reading index | ||
linear: true | ||
}, ondownload) | ||
self._range = { | ||
self._range = { | ||
...self._range, | ||
@@ -105,3 +107,3 @@ ...self._downloadRange | ||
if (self._range.length > -1) { | ||
self.feed.seek(self._range.byteOffset + self._range.length - 1, self._range, onend) | ||
self.feed.seek(self._range.byteOffset + self._range.length, self._range, onend) | ||
} else { | ||
@@ -148,3 +150,3 @@ self.pending = false | ||
if ((this._range.end !== -1 && this._range.start > this._range.end) || this._range.length === 0) { | ||
if ((this._range.end !== -1 && this._range.start >= this._range.end) || this._range.length === 0) { | ||
return this.push(null) | ||
@@ -151,0 +153,0 @@ } |
{ | ||
"name": "hypercore-byte-stream", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A Readable stream wrapper around Hypercore that supports reading byte ranges.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# hypercore-byte-stream | ||
[![Build Status](https://travis-ci.com/andrewosh/hypercore-byte-stream.svg?branch=master)](https://travis-ci.com/andrewosh/hypercore-byte-stream) | ||
A Readable stream wrapper around Hypercore that supports reading byte ranges. | ||
@@ -3,0 +5,0 @@ |
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
15865
396
48