Skip to content

downloadAndValidate

downloadAndValidate(options): Promise<Uint8Array<ArrayBufferLike>>

Defined in: packages/synapse-core/src/piece/download.ts:63

Download data from a URL, validate its PieceCID, and return as Uint8Array

This function:

  1. Downloads data from the URL
  2. Calculates PieceCID during streaming
  3. Collects all chunks into a Uint8Array
  4. Validates the calculated PieceCID matches the expected value
ParameterTypeDescription
optionsOptionsTypedownloadAndValidate.OptionsType

Promise<Uint8Array<ArrayBufferLike>>

Data downloadAndValidate.ReturnType

Errors downloadAndValidate.ErrorType

import * as Piece from '@filoz/synapse-core/piece'
const data = await Piece.downloadAndValidate({
url: 'https://example.com/piece',
expectedPieceCid: 'bafkzcib...',
})
console.log(data)