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

Side by Side Diff: utils/archive/input_stream.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library("input_stream"); 5 #library("input_stream");
6 6
7 #import("archive.dart", prefix: "archive"); 7 #import("archive.dart", prefix: "archive");
8 #import("entry.dart"); 8 #import("entry.dart");
9 #import("read_request.dart"); 9 #import("read_request.dart");
10 #import("utils.dart"); 10 #import("utils.dart");
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 attachFinalizer(this, (id) { 56 attachFinalizer(this, (id) {
57 if (id.value != null) call(FREE, id.value).then(() {}); 57 if (id.value != null) call(FREE, id.value).then(() {});
58 }, _id); 58 }, _id);
59 } 59 }
60 60
61 /** Whether this stream has finished reading entries. */ 61 /** Whether this stream has finished reading entries. */
62 bool get closed() => _id.value == null; 62 bool get closed() => _id.value == null;
63 63
64 /** 64 /**
65 * Reads the entire contents of the archive at once.
66 *
67 * Note that this is mutually exclusive with reading individual entries using
68 * [onEntry].
69 */
70 Future<List<CompleteArchiveEntry>> readAll() {
71 var completer = new Completer<List<Future<CompleteArchiveEntry>>>();
72 var result = <Future<CompleteArchiveEntry>>[];
73
74 this.onEntry = (entry) => result.add(entry.readAll());
75 this.onError = (e, stack) => completer.completeException(e, stack);
76 this.onClosed = () => completer.complete(result);
77
78 return completer.future.chain(Futures.wait);
79 }
80
81 /**
65 * Sets a callback to call when a new entry is read from the archive. 82 * Sets a callback to call when a new entry is read from the archive.
66 * 83 *
67 * The [ArchiveEntry] that's read from an archive initially only contains 84 * The [ArchiveEntry] that's read from an archive initially only contains
68 * header information such as the filename and permissions. To get the actual 85 * header information such as the filename and permissions. To get the actual
69 * data contained in the entry, use [ArchiveEntry.openInputStream]. 86 * data contained in the entry, use [ArchiveEntry.openInputStream].
70 * 87 *
71 * Since the entries are read in sequence from the archive, the data stream 88 * Since the entries are read in sequence from the archive, the data stream
72 * for one entry must be opened before the next entry is read from the 89 * for one entry must be opened before the next entry is read from the
73 * archive. The next entry will not be read until the return value of 90 * archive. The next entry will not be read until the return value of
74 * [callback] has completed. 91 * [callback] has completed.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 if (entry.isInputOpen) return entry.inputComplete; 154 if (entry.isInputOpen) return entry.inputComplete;
138 return new Future.immediate(null); 155 return new Future.immediate(null);
139 }); 156 });
140 future.onComplete((_) { 157 future.onComplete((_) {
141 _currentEntry = null; 158 _currentEntry = null;
142 entry.close(); 159 entry.close();
143 }); 160 });
144 return future; 161 return future;
145 } 162 }
146 } 163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698