@lumera/sdk-js
    Preparing search index...

    Class CascadeDownloader

    CascadeDownloader manages the complete file download workflow.

    This class integrates the SNApiClient and TaskManager to provide a simple, high-level API for downloading files from Cascade. It handles:

    • Download authentication for private files
    • Download task initiation
    • Task status monitoring until file is ready
    • File stream retrieval

    The current implementation uses a simulated signature for download_auth. In production, this should be replaced with a real wallet signature over the action ID using ADR-036 signArbitrary for private downloads.

    Index

    Constructors

    • Create a new CascadeDownloader instance

      Parameters

      • client: SNApiClient

        SNApiClient for making sn-api requests

      • signerAddress: string

        Bech32 address of the signer

      • signer: UniversalSigner

        Universal signer for signing operations

      • chainId: string

        Chain ID for signing operations

      Returns CascadeDownloader

    Methods

    • Convenience method to download a file by action ID

      This is a shorthand for calling downloadFile with just an action ID. Defaults to public download (no authentication).

      Parameters

      • actionId: string

        The blockchain action ID to download

      • OptionaltaskOptions: TaskManagerOptions

        Optional task monitoring configuration

      Returns Promise<ReadableStream<any>>

      Promise resolving to a ReadableStream of the file data

      const downloader = new CascadeDownloader(snapiClient);
      const stream = await downloader.download('action-123');
    • Download a file from Cascade storage

      This method orchestrates the complete download workflow:

      1. Prepares the download_auth signature (for private downloads)
      2. Initiates a download task via sn-api
      3. Monitors the task using SSE until the file is ready
      4. Retrieves and returns the file as a ReadableStream

      The returned stream can be processed incrementally, making it suitable for large files without loading them entirely into memory.

      Parameters

      • params: DownloadParams

        Download parameters including action ID and options

      Returns Promise<ReadableStream<any>>

      Promise resolving to a ReadableStream of the file data

      If any step of the download workflow fails

      const downloader = new CascadeDownloader(snapiClient, signerAddress, signer, chainId);

      // Download a public file
      const stream = await downloader.downloadFile({
      actionId: 'action-123'
      });

      // Download a private file (requires authentication)
      const privateStream = await downloader.downloadFile({
      actionId: 'action-456',
      isPrivate: true,
      taskOptions: {
      pollInterval: 2000,
      timeout: 300000
      }
      });

      // Process the stream
      const reader = stream.getReader();
      const chunks: Uint8Array[] = [];

      while (true) {
      const { done, value } = await reader.read();
      if (done) break;
      chunks.push(value);
      }

      // Combine chunks into a single Uint8Array
      const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
      const fileData = new Uint8Array(totalLength);
      let offset = 0;
      for (const chunk of chunks) {
      fileData.set(chunk, offset);
      offset += chunk.length;
      }
    • Convenience method to download a private file

      This is a shorthand for downloading a file that requires authentication.

      Parameters

      • actionId: string

        The blockchain action ID to download

      • OptionaltaskOptions: TaskManagerOptions

        Optional task monitoring configuration

      Returns Promise<ReadableStream<any>>

      Promise resolving to a ReadableStream of the file data

      const downloader = new CascadeDownloader(snapiClient);
      const stream = await downloader.downloadPrivate('action-456');