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

Unified Diff: utils/pub/io.dart

Issue 12090081: Add a Pub validator for READMEs that are invalid utf-8. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 years, 11 months 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
« no previous file with comments | « no previous file | utils/pub/package.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/io.dart
diff --git a/utils/pub/io.dart b/utils/pub/io.dart
index d45e9298a5797813cf71a7f08177ec98a0ef9c3a..8243a28190ad8bf2f88177c9f716baf275e05fbf 100644
--- a/utils/pub/io.dart
+++ b/utils/pub/io.dart
@@ -85,6 +85,16 @@ Future<String> readTextFile(file) {
});
}
+/// Reads the contents of the binary file [file], which can either be a [String]
+/// or a [File].
+List<int> readBinaryFile(file) {
+ var path = _getPath(file);
+ log.io("Reading binary file $path.");
+ var contents = new File(path).readAsBytesSync();
+ log.io("Read ${contents.length} bytes from $path.");
+ return contents;
+}
+
/// Creates [file] (which can either be a [String] or a [File]), and writes
/// [contents] to it. Completes when the file is written and closed.
///
@@ -109,6 +119,20 @@ Future<File> writeTextFile(file, String contents, {dontLogContents: false}) {
});
}
+/// Creates [file] (which can either be a [String] or a [File]), and writes
+/// [contents] to it.
+File writeBinaryFile(file, List<int> contents) {
+ var path = _getPath(file);
+ file = new File(path);
+
+ log.io("Writing ${contents.length} bytes to binary file $path.");
+ file.openSync(FileMode.WRITE)
+ ..writeListSync(contents, 0, contents.length)
+ ..closeSync();
+ log.fine("Wrote text file $path.");
+ return file;
+}
+
/// Asynchronously deletes [file], which can be a [String] or a [File]. Returns
/// a [Future] that completes when the deletion is done.
Future<File> deleteFile(file) {
« no previous file with comments | « no previous file | utils/pub/package.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698