Skip to content

Commit

Permalink
fix: simplify arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal committed Mar 20, 2020
1 parent f794152 commit 4384e2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/bare.js
Expand Up @@ -6,17 +6,16 @@ const isCID = node => !!(node && node[cidSymbol])
const sum = (x, y) => x + y

module.exports = (Block, codec) => {
const balanced = (opts = {}) => async function * (parts) {
const balanced = (limit=1000) => async function * (parts) {
parts = [...parts]
const limit = opts.limit || 1000
if (parts.length > limit) {
const size = Math.ceil(parts.length / Math.ceil(parts.length / limit))
const subparts = []
while (parts.length) {
const chunk = parts.splice(0, size)
const length = chunk.map(([l]) => l).reduce(sum)
let last
for await (const block of balanced(opts)(chunk)) {
for await (const block of balanced(limit)(chunk)) {
yield block
last = block
}
Expand Down
6 changes: 3 additions & 3 deletions test/test-basics.js
Expand Up @@ -26,7 +26,7 @@ test('basic inline buffer', async () => {
const testMany = async (i, limit) => {
const blocks = { 'dag-cbor': [], raw: [] }
let last
const balanced = main.balanced({ limit })
const balanced = main.balanced(limit)
for await (const block of main.from(mkgen(i), balanced)) {
const cid = await block.cid()
blocks[cid.codec].push(block)
Expand Down Expand Up @@ -83,7 +83,7 @@ test('read inline', async () => {
})

test('read nested full', async () => {
const balanced = main.balanced({ limit: 100 })
const balanced = main.balanced(100)
const [get, root] = await load(main.from(mkgen(500), balanced))
const data = await read(root, get)
const comp = await toBuffer(mkgen(500))
Expand All @@ -93,7 +93,7 @@ test('read nested full', async () => {

test('read nested sliding', async () => {
const buffer = await randomBytes(1024)
const balanced = main.balanced({ limit: 2 })
const balanced = main.balanced(2)
const [get, root] = await load(main.from(mkgen(10, buffer), balanced))
const data = await read(root, get)
const comp = await toBuffer(mkgen(10, buffer))
Expand Down

0 comments on commit 4384e2e

Please sign in to comment.