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' as archive; | 8 import 'archive.dart' as archive; |
9 import 'entry_request.dart'; | 9 import 'entry_request.dart'; |
10 import 'read_request.dart' as read; | 10 import 'read_request.dart' as read; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 * For internal use only. | 43 * For internal use only. |
44 */ | 44 */ |
45 Future inputComplete; | 45 Future inputComplete; |
46 | 46 |
47 ArchiveEntry.internal(this._properties, this._archiveId) { | 47 ArchiveEntry.internal(this._properties, this._archiveId) { |
48 attachFinalizer(this, (id) => call(FREE, id), _id); | 48 attachFinalizer(this, (id) => call(FREE, id), _id); |
49 } | 49 } |
50 | 50 |
51 /** Create a new [ArchiveEntry] with default values for all of its fields. */ | 51 /** Create a new [ArchiveEntry] with default values for all of its fields. */ |
52 static Future<ArchiveEntry> create() { | 52 static Future<ArchiveEntry> create() { |
53 return call(NEW).transform((properties) { | 53 return call(NEW).then((properties) { |
54 return new archive.ArchiveEntry.internal(properties, null); | 54 return new archive.ArchiveEntry.internal(properties, null); |
55 }); | 55 }); |
56 } | 56 } |
57 | 57 |
58 /** The id of the underlying archive entry. */ | 58 /** The id of the underlying archive entry. */ |
59 int get _id => _properties[0]; | 59 int get _id => _properties[0]; |
60 | 60 |
61 /** If this entry is a hardlink, this is the destination. Otherwise, null. */ | 61 /** If this entry is a hardlink, this is the destination. Otherwise, null. */ |
62 String get hardlink => _properties[1]; | 62 String get hardlink => _properties[1]; |
63 set hardlink(String value) => _set(SET_HARDLINK, 1, value); | 63 set hardlink(String value) => _set(SET_HARDLINK, 1, value); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 Future<CompleteArchiveEntry> readAll() { | 208 Future<CompleteArchiveEntry> readAll() { |
209 var stream = openInputStream(); | 209 var stream = openInputStream(); |
210 var buffer = <int>[]; | 210 var buffer = <int>[]; |
211 var completer = new Completer<List<int>>(); | 211 var completer = new Completer<List<int>>(); |
212 | 212 |
213 stream.onData = () => buffer.addAll(stream.read()); | 213 stream.onData = () => buffer.addAll(stream.read()); |
214 stream.onError = completer.completeException; | 214 stream.onError = completer.completeException; |
215 stream.onClosed = () => completer.complete(buffer); | 215 stream.onClosed = () => completer.complete(buffer); |
216 | 216 |
217 return Futures.wait([call(CLONE, _id), completer.future]) | 217 return Futures.wait([call(CLONE, _id), completer.future]) |
218 .transform((list) => new CompleteArchiveEntry._(list[0], list[1])); | 218 .then((list) => new CompleteArchiveEntry._(list[0], list[1])); |
219 } | 219 } |
220 | 220 |
221 /** | 221 /** |
222 * Set a property value with index [value] on the local representation of the | 222 * Set a property value with index [value] on the local representation of the |
223 * archive entry and on the native representation. | 223 * archive entry and on the native representation. |
224 */ | 224 */ |
225 void _set(int requestType, int index, value) { | 225 void _set(int requestType, int index, value) { |
226 _properties[index] = value; | 226 _properties[index] = value; |
227 // Since the native code processes messages in order, the SET_* messages | 227 // Since the native code processes messages in order, the SET_* messages |
228 // will be received and processed before any further messages. | 228 // will be received and processed before any further messages. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 var inputCompleter = new Completer(); | 270 var inputCompleter = new Completer(); |
271 inputComplete = inputCompleter.future; | 271 inputComplete = inputCompleter.future; |
272 | 272 |
273 _input = new ListInputStream(); | 273 _input = new ListInputStream(); |
274 // TODO(nweiz): Report errors once issue 3657 is fixed | 274 // TODO(nweiz): Report errors once issue 3657 is fixed |
275 var future = _consumeInput().chain((_) { | 275 var future = _consumeInput().chain((_) { |
276 if (!_input.closed) _input.markEndOfStream(); | 276 if (!_input.closed) _input.markEndOfStream(); |
277 // Asynchronously complete to give the InputStream callbacks a chance to | 277 // Asynchronously complete to give the InputStream callbacks a chance to |
278 // fire. | 278 // fire. |
279 return async(); | 279 return async(); |
280 }).transform((_) => inputCompleter.complete(null)); | 280 }).then((_) => inputCompleter.complete(null)); |
281 | 281 |
282 future.handleException((e) { | 282 future.handleException((e) { |
283 print(e); | 283 print(e); |
284 print(future.stackTrace); | 284 print(future.stackTrace); |
285 }); | 285 }); |
286 return _input; | 286 return _input; |
287 } | 287 } |
288 | 288 |
289 /** | 289 /** |
290 * Close this entry so that its input stream no longer produces data. | 290 * Close this entry so that its input stream no longer produces data. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 class CompleteArchiveEntry extends ArchiveEntry { | 328 class CompleteArchiveEntry extends ArchiveEntry { |
329 /** The contents of the entry as bytes. */ | 329 /** The contents of the entry as bytes. */ |
330 final List<int> contentBytes; | 330 final List<int> contentBytes; |
331 | 331 |
332 /** The contents of the entry as a string. */ | 332 /** The contents of the entry as a string. */ |
333 String get contents => new String.fromCharCodes(contentBytes); | 333 String get contents => new String.fromCharCodes(contentBytes); |
334 | 334 |
335 CompleteArchiveEntry._(List properties, this.contentBytes) | 335 CompleteArchiveEntry._(List properties, this.contentBytes) |
336 : super.internal(properties, null); | 336 : super.internal(properties, null); |
337 } | 337 } |
OLD | NEW |