Skip to content

maxFittingPieces

maxFittingPieces(options): number

Defined in: packages/synapse-core/src/sp/add-pieces-fits.ts:164

Length of the longest prefix of options.pieces that fits in one addPieces / createAndAdd message.

Equivalent to the largest n for which addPiecesFits returns true on pieces.slice(0, n), or 0 if none fit. Stops before the first piece with invalid metadata. Binary searches the prefix length, encoding the calldata O(log n) times instead of once per piece. Never throws.

Parameter Type Description
options LimiterOptions maxFittingPieces.OptionsType

number

Number of leading pieces that fit maxFittingPieces.OutputType

import { maxFittingPieces } from '@filoz/synapse-core/sp'

const count = maxFittingPieces({ kind: 'addPieces', dataSetId, legacyPieceStorageIdLimit, pieces })
const batch = pieces.slice(0, count)