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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
LimiterOptions |
maxFittingPieces.OptionsType |
Returns
Section titled “Returns”number
Number of leading pieces that fit maxFittingPieces.OutputType
Example
Section titled “Example”import { maxFittingPieces } from '@filoz/synapse-core/sp'
const count = maxFittingPieces({ kind: 'addPieces', dataSetId, legacyPieceStorageIdLimit, pieces })
const batch = pieces.slice(0, count)