Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ReadStream extends Readable {
this.tail = !!opts.tail
this.index = this.start
this.options = { wait: opts.wait !== false, ifAvailable: !!opts.ifAvailable, valueEncoding: opts.valueEncoding }
this.batch = opts.batch || 1
}

_open (cb) {
Expand All @@ -63,6 +64,21 @@ class ReadStream extends Readable {
this.push(null)
return cb(null)
}
if (this.batch > 1) {
const batchStart = this.index
const batchEnd = Math.min(batchStart + this.batch, this.end, this.feed.length)
if (batchStart < batchEnd) {
this.index = batchEnd
this.feed.getBatch(batchStart, batchEnd, this.options, (err, blocks) => {
if (err) return cb(err)
for (const block of blocks) {
this.push(block)
}
cb(null)
})
return
}
}
this.feed.get(this.index++, this.options, (err, block) => {
if (err) return cb(err)
this.push(block)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"hypercore": "^9.2.1",
"random-access-memory": "^3.1.1",
"standard": "^14.3.4",
"stream-collector": "^1.0.1",
"tape": "^5.0.1"
},
"scripts": {
"test": "standard && tape test.js"
"test": "standard && tape test/index.js"
},
"repository": {
"type": "git",
Expand Down
109 changes: 0 additions & 109 deletions test.js

This file was deleted.

27 changes: 27 additions & 0 deletions test/helpers/create-tracking-ram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const ram = require('random-access-memory')

module.exports = function () {
const logByFilename = {}
const factory = function (filename) {
const memory = ram()
const log = []
logByFilename[filename] = log
return {
read: logAndForward('read'),
write: logAndForward('write'),
del: logAndForward('del')
}

function logAndForward (op) {
return function () {
var statement = {}
statement[op] = [].slice.apply(arguments)
statement[op].pop()
log.push(statement)
return memory[op].apply(memory, arguments)
}
}
}
factory.log = logByFilename
return factory
}
Loading