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

Unified Diff: utils/archive/entry.dart

Issue 10830191: Add ArchiveInputStream.readAll. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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/archive/entry_request.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
« no previous file with comments | « no previous file | utils/archive/entry_request.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698