Chromium Code Reviews| Index: utils/archive/entry.dart |
| diff --git a/utils/archive/entry.dart b/utils/archive/entry.dart |
| index 7f940265ac4973c9bf11bff1c59f12b8c3970bb6..a69e990d679ceb0ca28354a92b126dc89cb03966 100644 |
| --- a/utils/archive/entry.dart |
| +++ b/utils/archive/entry.dart |
| @@ -201,6 +201,26 @@ class ArchiveEntry { |
| } |
| /** |
| + * Consumes the entire contents of this entry at once and returns it wrapped |
| + * in a [CompleteArchiveEntry]. All metadata fields in the returned entry are |
| + * copies of the fields in this entry. |
| + * |
| + * This may not be called [openInputStream] is called, and vice versa. |
|
Bob Nystrom
2012/08/06 23:44:28
Missing some word here.
nweiz
2012/08/07 00:57:12
Done.
|
| + */ |
| + Future<CompleteArchiveEntry> readAll() { |
| + var stream = openInputStream(); |
| + var buffer = <int>[]; |
| + var completer = new Completer<List<int>>(); |
| + |
| + stream.onData = () => buffer.addAll(stream.read()); |
| + stream.onError = completer.completeException; |
| + stream.onClosed = () => completer.complete(buffer); |
| + |
| + return Futures.wait([call(CLONE, _id), completer.future]) |
| + .transform((list) => new CompleteArchiveEntry._(list[0], list[1])); |
| + } |
| + |
| + /** |
| * Set a property value with index [value] on the local representation of the |
| * archive entry and on the native representation. |
| */ |
| @@ -302,3 +322,18 @@ class ArchiveEntry { |
| }); |
| } |
| } |
| + |
| +/** |
| + * An [ArchiveEntry] that contains the complete decompressed contents of the |
| + * file. |
| + */ |
| +class CompleteArchiveEntry extends ArchiveEntry { |
| + /** The contents of the entry as bytes. */ |
| + final List<int> contentBytes; |
| + |
| + /** The contents of the entry as a string. */ |
| + String get contents() => new String.fromCharCodes(contentBytes); |
| + |
| + CompleteArchiveEntry._(List properties, this.contentBytes) |
| + : super.internal(properties, null); |
| +} |