Two simple test files for dart.io
.
- Run
dart download.dart
- Run
dart extract.dart
Have fun..
import 'dart:io'; | |
final metaPackageUrl = | |
'https://storage.googleapis.com/pub-packages/packages/meta-1.1.7.tar.gz'; | |
void main() async { | |
final client = HttpClient(); | |
final req = await client.getUrl(Uri.parse(metaPackageUrl)); | |
final res = await req.close(); | |
print('status: ${res.statusCode}'); | |
final data = <int>[]; | |
await for (final chunk in res) { | |
data.addAll(chunk); | |
} | |
await File('output.tar.gz').writeAsBytes(data); | |
} |
import 'dart:io'; | |
void main() async { | |
await Directory('output').delete(recursive: true).catchError((_) {}); | |
await Directory('output').create(); | |
final p = await Process.start('tar', [ | |
'--extract', | |
'--gunzip', | |
'--no-same-owner', | |
'--no-same-permissions', | |
'--directory', | |
'output', | |
]); | |
await File('output.tar.gz').openRead().pipe(p.stdin); | |
final exitcode = await p.exitCode; | |
print('exitcode: $exitcode'); | |
} |