Skip to content

Instantly share code, notes, and snippets.

@jonasfj
Created February 11, 2019 15:41
Show Gist options
  • Save jonasfj/df09d7855294a1cf71a8de55d688b573 to your computer and use it in GitHub Desktop.
Save jonasfj/df09d7855294a1cf71a8de55d688b573 to your computer and use it in GitHub Desktop.

Two simple test files for dart.io.

  1. Run dart download.dart
  2. 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');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment