Chromium Code Reviews| Index: utils/pub/io.dart |
| diff --git a/utils/pub/io.dart b/utils/pub/io.dart |
| index 79f0a06524cc5b91b5e953fdf03d42ccb5b6ca82..e392fec3b4755ceac53af913f9abdf833c4992cd 100644 |
| --- a/utils/pub/io.dart |
| +++ b/utils/pub/io.dart |
| @@ -69,6 +69,7 @@ Future<bool> fileExists(file) { |
| (exists) => "File $path ${exists ? 'exists' : 'does not exist'}."); |
| } |
| +// TODO(rnystrom): Get rid of this and only use sync. |
| /// Reads the contents of the text file [file], which can either be a [String] |
| /// or a [File]. |
| Future<String> readTextFile(file) { |
| @@ -85,6 +86,23 @@ Future<String> readTextFile(file) { |
| }); |
| } |
| +/// Reads the contents of the text file [file], which can either be a [String] |
| +/// or a [File]. |
| +String readTextFileSync(file) { |
|
nweiz
2013/01/31 22:38:53
I'm not a big fan of this intermediate duplication
Bob Nystrom
2013/02/01 16:53:29
Yup. Once that patch lands, this will be gone.
|
| + var path = _getPath(file); |
| + log.io("Reading text file $path."); |
| + var contents = new File(path).readAsStringSync(Encoding.UTF_8); |
| + |
| + // Sanity check: don't spew a huge file. |
| + if (contents.length < 1024 * 1024) { |
| + log.fine("Read $path. Contents:\n$contents"); |
| + } else { |
| + log.fine("Read ${contents.length} characters 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. |
| /// |
| @@ -289,6 +307,7 @@ Future<List<String>> listDir(dir, |
| return doList(_getDirectory(dir), new Set<String>()); |
| } |
| +// TODO(rnystrom): Migrate everything over to the sync one and get rid of this. |
| /// Asynchronously determines if [dir], which can be a [String] directory path |
| /// or a [Directory], exists on the file system. Returns a [Future] that |
| /// completes with the result. |
| @@ -300,6 +319,11 @@ Future<bool> dirExists(dir) { |
| "${exists ? 'exists' : 'does not exist'}."); |
| } |
| +/// Determines if [dir], which can be a [String] directory path or a |
| +/// [Directory], exists on the file system. Returns a [Future] that completes |
| +/// with the result. |
| +bool dirExistsSync(dir) => _getDirectory(dir).existsSync(); |
| + |
| /// "Cleans" [dir]. If that directory already exists, it will be deleted. Then a |
| /// new empty directory will be created. Returns a [Future] that completes when |
| /// the new clean directory is created. |