Socket
Socket
Sign inDemoInstall

hypercore-byte-stream

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hypercore-byte-stream - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

15

index.js

@@ -28,3 +28,3 @@ const assert = require('assert')

start ({ feed, blockOffset, blockLength, byteOffset, byteLength} = {}) {
start ({ feed, blockOffset, blockLength, byteOffset, byteLength } = {}) {
assert(!this.feed, 'Can only provide options once (in the constructor, or asynchronously).')

@@ -52,7 +52,12 @@

_seek (offset, cb) {
// end + 1 so we can support seeks to the end of the file
this.feed.seek(offset, { start: this._range.start, end: this._range.end + 1 }, cb)
}
_open (size) {
let self = this
const self = this
let missing = 1
this._opened = true
this._opened = true
this.feed.ready(err => {

@@ -62,3 +67,3 @@ if (err || this.destroyed) return this.destroy(err)

if (this._range.byteOffset === -1) return onstart(null, this._range.start, 0)
this.feed.seek(this._range.byteOffset, this._range, onstart)
this._seek(this._range.byteOffset, onstart)
})

@@ -106,3 +111,3 @@

if (self._range.length > -1) {
self.feed.seek(self._range.byteOffset + self._range.length, self._range, onend)
self._seek(self._range.byteOffset + self._range.length, onend)
} else {

@@ -109,0 +114,0 @@ self.pending = false

{
"name": "hypercore-byte-stream",
"version": "1.0.7",
"version": "1.0.8",
"description": "A Readable stream wrapper around Hypercore that supports reading byte ranges.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,2 +5,1 @@ const { createLocal } = require('./helpers/create')

testSuite('local', createLocal)

@@ -7,7 +7,7 @@ const ram = require('random-access-memory')

function createLocal (numRecords, recordSize, cb) {
let core = hypercore(ram)
const core = hypercore(ram)
let records = []
const records = []
for (let i = 0; i < numRecords; i++) {
let record = Buffer.allocUnsafe(recordSize).fill(Math.floor(Math.random() * 10))
const record = Buffer.allocUnsafe(recordSize).fill(Math.floor(Math.random() * 10))
records.push(record)

@@ -18,3 +18,3 @@ }

if (err) return cb(err)
let stream = createStream()
const stream = createStream()
return cb(null, core, core, stream, records)

@@ -25,7 +25,7 @@ })

function createRemote (numRecords, recordSize, cb) {
let core1 = hypercore(ram, { sparse: true })
const core1 = hypercore(ram, { sparse: true })
let records = []
const records = []
for (let i = 0; i < numRecords; i++) {
let record = Buffer.allocUnsafe(recordSize).fill(Math.floor(Math.random() * 10))
const record = Buffer.allocUnsafe(recordSize).fill(Math.floor(Math.random() * 10))
records.push(record)

@@ -37,8 +37,8 @@ }

let core2 = hypercore(ram, core1.key, { sparse: true })
const core2 = hypercore(ram, core1.key, { sparse: true })
let s1 = core1.replicate(true, { live: true })
const s1 = core1.replicate(true, { live: true })
s1.pipe(core2.replicate(false, { live: true })).pipe(s1)
let stream = createStream()
const stream = createStream()
return cb(null, core1, core2, stream, records)

@@ -45,0 +45,0 @@ })

@@ -8,3 +8,3 @@ const test = require('tape')

t.error(err, 'create stream ok')
let combined = Buffer.concat(records, 1000)
const combined = Buffer.concat(records, 1000)

@@ -17,3 +17,3 @@ stream.start({

stream.on('data', data => {
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
offset += data.length

@@ -31,3 +31,3 @@ })

t.error(err, 'create stream ok')
let combined = Buffer.concat(records.slice(2), 800)
const combined = Buffer.concat(records.slice(2), 800)

@@ -41,3 +41,3 @@ stream.start({

stream.on('data', data => {
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
offset += data.length

@@ -55,6 +55,6 @@ })

t.error(err, 'create stream ok')
let combined = Buffer.concat(records.slice(5), 500)
const combined = Buffer.concat(records.slice(5), 500)
stream.start({
feed: output,
feed: output,
byteOffset: 500,

@@ -67,3 +67,3 @@ byteLength: 50

t.same(data.length, 50)
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
offset += data.length

@@ -81,3 +81,3 @@ })

t.error(err, 'create stream ok')
let combined = Buffer.concat(records.slice(5), 500)
const combined = Buffer.concat(records.slice(5), 500)

@@ -94,3 +94,3 @@ stream.start({

t.same(data.length, 50)
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
offset += data.length

@@ -108,3 +108,3 @@ })

t.error(err, 'create stream ok')
let combined = Buffer.concat(records.slice(5), 500)
const combined = Buffer.concat(records.slice(5), 500)

@@ -122,3 +122,3 @@ stream.start({

t.same(data.length, 50)
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
offset += data.length

@@ -135,3 +135,3 @@ })

t.error(err, 'create stream ok')
let combined = Buffer.concat(records.slice(5), 500)
const combined = Buffer.concat(records.slice(5), 500)

@@ -146,7 +146,7 @@ stream.start({

let offset = 0
const offset = 0
stream.on('data', data => {
t.fail('data should not be emitted')
})
stream.on('end',() => {
stream.on('end', () => {
t.end()

@@ -163,3 +163,3 @@ })

t.error(err, 'create stream ok')
let combined = Buffer.concat(records.slice(5), 500)
const combined = Buffer.concat(records.slice(5), 500)

@@ -169,3 +169,3 @@ stream.start({

byteOffset: 500,
byteLength: 700,
byteLength: 700
})

@@ -184,3 +184,3 @@

}
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
offset += data.length

@@ -211,3 +211,2 @@ })

test(`${tag}: cannot call start after streaming\'s started`, t => {

@@ -243,3 +242,3 @@ t.plan(2)

t.error(err, 'create stream ok')
let combined = Buffer.concat(records, 1000)
const combined = Buffer.concat(records, 1000)

@@ -253,3 +252,3 @@ stream.start({

stream.on('data', data => {
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
t.same(data, combined.slice(offset, offset + data.length), 'chunks are the same')
offset += data.length

@@ -256,0 +255,0 @@ if (count++ === 5) {

@@ -5,2 +5,1 @@ const { createRemote } = require('./helpers/create')

testSuite('remote', createRemote)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc