Files
archy/apps/web5-dwn/node_modules/ipfs-unixfs-importer/src/layout/balanced.ts
T
Dorian 0d073fa89e Add comprehensive installation and setup documentation
- Add GETTING_STARTED.md with quick start guide and development modes
- Add INSTALL.sh automated installation script
- Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md
- Add QUICK_REFERENCE.md for common commands
- Add SETUP_GUIDE.md with detailed setup instructions
- Update README.md with improved project overview
- Add did-wallet app dependencies and node_modules
2026-01-27 17:18:21 +00:00

28 lines
735 B
TypeScript

import batch from 'it-batch'
import type { FileLayout } from './index.js'
import type { InProgressImportResult } from '../index.js'
const DEFAULT_MAX_CHILDREN_PER_NODE = 174
export interface BalancedOptions {
maxChildrenPerNode?: number
}
export function balanced (options?: BalancedOptions): FileLayout {
const maxChildrenPerNode = options?.maxChildrenPerNode ?? DEFAULT_MAX_CHILDREN_PER_NODE
return async function balancedLayout (source, reduce): Promise<InProgressImportResult> {
const roots = []
for await (const chunked of batch(source, maxChildrenPerNode)) {
roots.push(await reduce(chunked))
}
if (roots.length > 1) {
return balancedLayout(roots, reduce)
}
return roots[0]
}
}