downloadToFile method
Downloads a file directly to disk path (without loading whole file into memory) For native platforms (Windows, macOS, Linux, Android, iOS): uses actual file system paths For web: triggers browser download dialog to save the file
if its a blossom url (sha256 in url), blossom is used to download
if its a public url, the file is downloaded directly
serverUrls and pubkey are used to download from blossom
if serverUrls is null, the userServerList is fetched from nostr (using the pubkey).
if both serverUrls and pubkey are null, throws an error.
Implementation
Future<void> downloadToFile({
required String url,
required String outputPath,
bool useAuth = false,
List<String>? serverUrls,
String? pubkey,
}) async {
// Regular expression to match SHA256 in URLs
final sha256Match = sha256Regex.firstMatch(url);
if (sha256Match != null) {
// This is a blossom URL, handle it using blossom protocol
final sha256 = sha256Match.group(1)!;
// Download using blossom to file
return await _blossom.downloadBlobToFile(
sha256: sha256,
outputPath: outputPath,
useAuth: useAuth,
serverUrls: serverUrls,
pubkeyToFetchUserServerList: pubkey,
);
} else {
// Direct download for non-blossom URLs
return await _blossom.directDownloadToFile(
url: Uri.parse(url),
outputPath: outputPath,
);
}
}