Create a new CascadeDownloader instance
SNApiClient for making sn-api requests
Bech32 address of the signer
Universal signer for signing operations
Chain ID for signing operations
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).
The blockchain action ID to download
OptionaltaskOptions: TaskManagerOptionsOptional task monitoring configuration
Promise resolving to a ReadableStream of the file data
Download a file from Cascade storage
This method orchestrates the complete download workflow:
The returned stream can be processed incrementally, making it suitable for large files without loading them entirely into memory.
Download parameters including action ID and options
Promise resolving to a ReadableStream of the file data
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.
The blockchain action ID to download
OptionaltaskOptions: TaskManagerOptionsOptional task monitoring configuration
Promise resolving to a ReadableStream of the file data
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:
Remarks
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.