Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2478)

Unified Diff: dart/tools/download_file.dart

Issue 57483005: Add tools/download_file.dart helper + download_contentshell shell/bat script included in the editor… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« dart/editor/build/build.py ('K') | « dart/editor/build/build.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/tools/download_file.dart
diff --git a/dart/tools/download_file.dart b/dart/tools/download_file.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8ddeb9928f553b74703fce96bf4c2eddaa2d3b9e
--- /dev/null
+++ b/dart/tools/download_file.dart
@@ -0,0 +1,52 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:io';
+
+Future downloadFile(Uri url, String destination) {
+ var client = new HttpClient();
+ return client.getUrl(url)
+ .then((HttpClientRequest request) => request.close())
+ .then((HttpClientResponse response) {
+ if (response.statusCode != HttpStatus.OK) {
+ throw new Exception("Http status code (${response.statusCode}) "
+ "was not 200. Aborting.");
+ }
+ var sink = new File(destination).openWrite();
+ return response.pipe(sink).then((_) {
+ client.close();
+ });
+ });
+}
+
+void main(List<String> arguments) {
+ die(String message) {
+ print(message);
+ exit(1);
+ }
+
+ note(String message) {
+ print(message);
+ }
+
+ if (arguments.length != 2) {
+ var scriptName = Platform.script.pathSegments.last;
+ die("Usage dart $scriptName <url> <destination-file>");
+ }
+
+ var url = Uri.parse(arguments[0]);
+ var destination = arguments[1];
+
+ if (!['http', 'https'].contains(url.scheme)) {
+ die("Unsupported scheme in uri $url");
+ }
+
+ note("Downloading $url to $destination.");
+ downloadFile(url, destination).then((_) {
+ note("Download finished.");
+ }).catchError((error) {
+ die("An unexpected error occured: $error.");
+ });
+}
« dart/editor/build/build.py ('K') | « dart/editor/build/build.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698