downloadAndValidate
function downloadAndValidate(response, expectedPieceCid): Promise<Uint8Array<ArrayBufferLike>>;
Defined in: packages/synapse-sdk/src/piece/download.ts:31
Download data from a Response object, validate its PieceCID, and return as Uint8Array
This function:
- Streams data from the Response body
- Calculates PieceCID during streaming
- Collects all chunks into a Uint8Array
- Validates the calculated PieceCID matches the expected value
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
response | Response | The Response object from a fetch() call |
expectedPieceCid | string | PieceLink | The expected PieceCID to validate against |
Returns
Section titled “Returns”Promise
<Uint8Array
<ArrayBufferLike
>>
The downloaded data as a Uint8Array
Throws
Section titled “Throws”Error if PieceCID validation fails or download errors occur
Example
Section titled “Example”const response = await fetch(url)const data = await downloadAndValidate(response, 'bafkzcib...')