Chromium Code Reviews| OLD | NEW |
|---|---|
| 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("entry"); | 5 #library("entry"); |
| 6 | 6 |
| 7 #import("dart:io"); | 7 #import("dart:io"); |
| 8 #import("archive.dart", prefix: "archive"); | 8 #import("archive.dart", prefix: "archive"); |
| 9 #import("entry_request.dart"); | 9 #import("entry_request.dart"); |
| 10 #import("read_request.dart", prefix: 'read'); | 10 #import("read_request.dart", prefix: 'read'); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 /** Whether [openInputStream] has been called. */ | 194 /** Whether [openInputStream] has been called. */ |
| 195 bool get isInputOpen() => _input != null; | 195 bool get isInputOpen() => _input != null; |
| 196 | 196 |
| 197 /** Create a deep copy of this [ArchiveEntry]. */ | 197 /** Create a deep copy of this [ArchiveEntry]. */ |
| 198 Future<ArchiveEntry> clone() { | 198 Future<ArchiveEntry> clone() { |
| 199 return call(CLONE, _id). | 199 return call(CLONE, _id). |
| 200 transform((array) => new archive.ArchiveEntry.internal(array, null)); | 200 transform((array) => new archive.ArchiveEntry.internal(array, null)); |
| 201 } | 201 } |
| 202 | 202 |
| 203 /** | 203 /** |
| 204 * Consumes the entire contents of this entry at once and returns it wrapped | |
| 205 * in a [CompleteArchiveEntry]. All metadata fields in the returned entry are | |
| 206 * copies of the fields in this entry. | |
| 207 * | |
| 208 * 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.
| |
| 209 */ | |
| 210 Future<CompleteArchiveEntry> readAll() { | |
| 211 var stream = openInputStream(); | |
| 212 var buffer = <int>[]; | |
| 213 var completer = new Completer<List<int>>(); | |
| 214 | |
| 215 stream.onData = () => buffer.addAll(stream.read()); | |
| 216 stream.onError = completer.completeException; | |
| 217 stream.onClosed = () => completer.complete(buffer); | |
| 218 | |
| 219 return Futures.wait([call(CLONE, _id), completer.future]) | |
| 220 .transform((list) => new CompleteArchiveEntry._(list[0], list[1])); | |
| 221 } | |
| 222 | |
| 223 /** | |
| 204 * Set a property value with index [value] on the local representation of the | 224 * Set a property value with index [value] on the local representation of the |
| 205 * archive entry and on the native representation. | 225 * archive entry and on the native representation. |
| 206 */ | 226 */ |
| 207 void _set(int requestType, int index, value) { | 227 void _set(int requestType, int index, value) { |
| 208 _properties[index] = value; | 228 _properties[index] = value; |
| 209 // Since the native code processes messages in order, the SET_* messages | 229 // Since the native code processes messages in order, the SET_* messages |
| 210 // will be received and processed before any further messages. | 230 // will be received and processed before any further messages. |
| 211 call(requestType, _id, [value]).then((_) {}); | 231 call(requestType, _id, [value]).then((_) {}); |
| 212 } | 232 } |
| 213 | 233 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 return async(); | 315 return async(); |
| 296 }).chain((_) { | 316 }).chain((_) { |
| 297 if (_input.closed || _archiveId == null || data == null) { | 317 if (_input.closed || _archiveId == null || data == null) { |
| 298 return new Future.immediate(null); | 318 return new Future.immediate(null); |
| 299 } | 319 } |
| 300 _input.write(data); | 320 _input.write(data); |
| 301 return _consumeInput(); | 321 return _consumeInput(); |
| 302 }); | 322 }); |
| 303 } | 323 } |
| 304 } | 324 } |
| 325 | |
| 326 /** | |
| 327 * An [ArchiveEntry] that contains the complete decompressed contents of the | |
| 328 * file. | |
| 329 */ | |
| 330 class CompleteArchiveEntry extends ArchiveEntry { | |
| 331 /** The contents of the entry as bytes. */ | |
| 332 final List<int> contentBytes; | |
| 333 | |
| 334 /** The contents of the entry as a string. */ | |
| 335 String get contents() => new String.fromCharCodes(contentBytes); | |
| 336 | |
| 337 CompleteArchiveEntry._(List properties, this.contentBytes) | |
| 338 : super.internal(properties, null); | |
| 339 } | |
| OLD | NEW |