# createPieceBatcher

> **createPieceBatcher**(`client`, `options`): [`PieceBatcher`](/reference/filoz/synapse-core/sp/type-aliases/piecebatcher/)

Defined in: [packages/synapse-core/src/sp/create-piece-batcher.ts:138](https://github.com/FilOzone/synapse-sdk/blob/5a206712436ab6bcc46c2a9e3774fc873b328e0f/packages/synapse-core/src/sp/create-piece-batcher.ts#L138)

Create a stateful piece batcher that parks/pulls immediately and coalesces addPieces.

`upload` and `pull` run per-piece I/O right away (`upload` uses the
streaming CommP-last protocol for bytes and streams). The tumbling window
only batches the on-chain addPieces (or createDataSetAndAddPieces) call.
Pull authorization uses `signAddPieces` for that one piece; flush signs a
new extraData for the whole window.

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `client` | `Client`\<`Transport`, `Chain`, `Account`\> | Wallet client used to sign and submit. |
| `options` | [`OptionsType`](/reference/filoz/synapse-core/sp/namespaces/createpiecebatcher/type-aliases/optionstype/) | [createPieceBatcher.OptionsType](/reference/filoz/synapse-core/sp/namespaces/createpiecebatcher/type-aliases/optionstype/) |

## Returns

[`PieceBatcher`](/reference/filoz/synapse-core/sp/type-aliases/piecebatcher/)

Batcher [createPieceBatcher.ReturnType](/reference/filoz/synapse-core/sp/namespaces/createpiecebatcher/type-aliases/returntype/)

## Example

```ts
import { createPieceBatcher } from '@filoz/synapse-core/sp'

const batcher = createPieceBatcher(client, { dataSet })
await Promise.all([
  batcher.upload({ data: fileA }),
  batcher.pull({ pieceCid, sourceUrl }),
])
await batcher.close()
```