Skip to content

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:

  1. Streams data from the Response body
  2. Calculates PieceCID during streaming
  3. Collects all chunks into a Uint8Array
  4. Validates the calculated PieceCID matches the expected value
ParameterTypeDescription
responseResponseThe Response object from a fetch() call
expectedPieceCidstring | PieceLinkThe expected PieceCID to validate against

Promise<Uint8Array<ArrayBufferLike>>

The downloaded data as a Uint8Array

Error if PieceCID validation fails or download errors occur

const response = await fetch(url)
const data = await downloadAndValidate(response, 'bafkzcib...')