Download to a File
Stream decrypted bytes directly to disk instead of buffering in memory.
rust
use sia_storage::DownloadOptions;
let mut file = tokio::fs::File::create("output.bin").await?;
let mut reader = sdk.download(&obj, DownloadOptions::default())?;
tokio::io::copy(&mut reader, &mut file).await?;go
file, err := os.Create("output.bin")
if err != nil {
panic(err)
}
defer file.Close()
if err := client.Download(ctx, file, obj); err != nil {
panic(err)
}python
with open("output.bin", "wb") as file:
async with sdk.download(obj, DownloadOptions()) as d:
await d.write_to(file)javascript
import { open } from 'node:fs/promises'
import { Writable } from 'node:stream'
const file = await open('output.bin', 'w')
const stream = sdk.download(obj)
await stream.pipeTo(Writable.toWeb(file.createWriteStream()))
await file.close()javascript
// Collect the stream into a Blob, then trigger a browser download.
const stream = sdk.download(obj)
const blob = await new Response(stream).blob()
const url = URL.createObjectURL(blob)
const a = Object.assign(document.createElement('a'), {
href: url,
download: 'output.bin',
})
a.click()
URL.revokeObjectURL(url)