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

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: Actually use the validator. 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
Index: utils/pub/io.dart
diff --git a/utils/pub/io.dart b/utils/pub/io.dart
index 79f0a06524cc5b91b5e953fdf03d42ccb5b6ca82..48c4901792a6adb21b9d33e8f291a2b6c193c61d 100644
--- a/utils/pub/io.dart
+++ b/utils/pub/io.dart
@@ -85,6 +85,15 @@ Future<String> readTextFile(file) {
});
}
+/// Reads the contents of the binary file [file], which can either be a [String]
+/// or a [File].
+Future<List<int>> readByteFile(file) {
Bob Nystrom 2013/01/31 19:08:29 "Byte" -> "Binary"? "ByteFile" reads strangely to
nweiz 2013/01/31 21:39:10 Done.
+ var path = _getPath(file);
+ return log.ioAsync("Reading byte file $path.",
+ new File(path).readAsBytes(),
Bob Nystrom 2013/01/31 19:08:29 Feel free to make this sync if you prefer.
nweiz 2013/01/31 21:39:10 Done.
+ (contents) => "Read ${contents.length} bytes from $path.");
+}
+
/// 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 +118,22 @@ Future<File> writeTextFile(file, String contents, {dontLogContents: false}) {
});
}
+/// Creates [file] (which can either be a [String] or a [File]), and writes
+/// [contents] to it. Completes when the file is written and closed.
+Future<File> writeByteFile(file, List<int> contents) {
Bob Nystrom 2013/01/31 19:08:29 Byte -> Binary.
nweiz 2013/01/31 21:39:10 Done.
+ var path = _getPath(file);
+ file = new File(path);
+
+ log.io("Writing ${contents.length} characters to binary file $path.");
Bob Nystrom 2013/01/31 19:08:29 "characters" -> "bytes".
nweiz 2013/01/31 21:39:10 Done.
+ return file.open(FileMode.WRITE).then((opened) {
+ return opened.writeList(contents, 0, contents.length)
+ .then((_) => opened.close());
+ }).then((_) {
+ log.fine("Wrote text file $path.");
+ return file;
+ });
Bob Nystrom 2013/01/31 19:08:29 then() then() then() Make this sync?
nweiz 2013/01/31 21:39:10 Done.
+}
+
/// 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) {

Powered by Google App Engine
This is Rietveld 408576698