Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using dart to download a file

Tags:

dart

Can we use dart to download a file?

For example in python

like image 327
Budi Sutrisno Avatar asked Aug 03 '13 13:08

Budi Sutrisno


1 Answers

Shailen's response is correct and can even be a little shorter with Stream.pipe.

import 'dart:io';

main() async {
  final request = await HttpClient().getUrl(Uri.parse('http://example.com'));
  final response = await request.close();
  response.pipe(File('foo.txt').openWrite());
}
like image 61
Alexandre Ardhuin Avatar answered Sep 29 '22 00:09

Alexandre Ardhuin