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

Side by Side Diff: utils/archive/input_stream.dart

Issue 10832116: Attach the native entry struct to the ArchiveEntry object. (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("entry.dart"); 8 #import("entry.dart");
8 #import("read_request.dart"); 9 #import("read_request.dart");
9 #import("utils.dart"); 10 #import("utils.dart");
10 11
11 /** 12 /**
12 * A stream of [ArchiveEntry]s being read from an archive. 13 * A stream of [ArchiveEntry]s being read from an archive.
13 * 14 *
14 * This is accessible via [ArchiveReader]. 15 * This is accessible via [ArchiveReader].
15 */ 16 */
16 class ArchiveInputStream { 17 class ArchiveInputStream {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 109
109 /** 110 /**
110 * Consumes and emits all [ArchiveEntries] in this archive. 111 * Consumes and emits all [ArchiveEntries] in this archive.
111 */ 112 */
112 Future _consumeHeaders() { 113 Future _consumeHeaders() {
113 if (closed) return new Future.immediate(null); 114 if (closed) return new Future.immediate(null);
114 var data; 115 var data;
115 return call(NEXT_HEADER, _id.value).chain((_data) { 116 return call(NEXT_HEADER, _id.value).chain((_data) {
116 data = _data; 117 data = _data;
117 if (data == null) return new Future.immediate(null); 118 if (data == null) return new Future.immediate(null);
118 return _emit(new ArchiveEntry(_id.value, data)). 119 return _emit(new archive.ArchiveEntry.internal(data, _id.value)).
119 chain((_) => _consumeHeaders()); 120 chain((_) => _consumeHeaders());
120 }); 121 });
121 } 122 }
122 123
123 /** 124 /**
124 * Emits [entry] to the [onEntry] callback. Returns a [Future] that will 125 * Emits [entry] to the [onEntry] callback. Returns a [Future] that will
125 * complete once the callback's return value completes and the entry's data 126 * complete once the callback's return value completes and the entry's data
126 * has been fully consumed. 127 * has been fully consumed.
127 */ 128 */
128 Future _emit(ArchiveEntry entry) { 129 Future _emit(ArchiveEntry entry) {
129 _currentEntry = entry; 130 _currentEntry = entry;
130 var future = _onEntryCompleter.future.chain((onEntry) { 131 var future = _onEntryCompleter.future.chain((onEntry) {
131 if (closed) return new Future.immediate(null); 132 if (closed) return new Future.immediate(null);
132 var result = onEntry(entry); 133 var result = onEntry(entry);
133 if (result is Future) return result; 134 if (result is Future) return result;
134 return new Future.immediate(null); 135 return new Future.immediate(null);
135 }).chain((_) { 136 }).chain((_) {
136 if (entry.isInputOpen) return entry.inputComplete; 137 if (entry.isInputOpen) return entry.inputComplete;
137 return new Future.immediate(null); 138 return new Future.immediate(null);
138 }); 139 });
139 future.onComplete((_) { 140 future.onComplete((_) {
140 _currentEntry = null; 141 _currentEntry = null;
141 entry.close(); 142 entry.close();
142 }); 143 });
143 return future; 144 return future;
144 } 145 }
145 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698