| 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 reader; | 5 library reader; |
| 6 | 6 |
| 7 import 'input_stream.dart'; | 7 import 'input_stream.dart'; |
| 8 import 'options.dart'; | 8 import 'options.dart'; |
| 9 import 'read_request.dart'; | 9 import 'read_request.dart'; |
| 10 import 'utils.dart'; | 10 import 'utils.dart'; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 * Begins extracting from [file]. | 53 * Begins extracting from [file]. |
| 54 * | 54 * |
| 55 * [block_size] only needs to be specified for reading from devices that | 55 * [block_size] only needs to be specified for reading from devices that |
| 56 * require strict I/O blocking. | 56 * require strict I/O blocking. |
| 57 */ | 57 */ |
| 58 Future<ArchiveInputStream> openFilename(String file, [int block_size=16384]) { | 58 Future<ArchiveInputStream> openFilename(String file, [int block_size=16384]) { |
| 59 var id; | 59 var id; |
| 60 return _createArchive().chain((_id) { | 60 return _createArchive().chain((_id) { |
| 61 id = _id; | 61 id = _id; |
| 62 return call(OPEN_FILENAME, id, [file, block_size]); | 62 return call(OPEN_FILENAME, id, [file, block_size]); |
| 63 }).transform((_) => new ArchiveInputStream(id)); | 63 }).then((_) => new ArchiveInputStream(id)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 /** Begins extracting from [data], which should be a list of bytes. */ | 66 /** Begins extracting from [data], which should be a list of bytes. */ |
| 67 Future<ArchiveInputStream> openData(List<int> data) { | 67 Future<ArchiveInputStream> openData(List<int> data) { |
| 68 var id; | 68 var id; |
| 69 return _createArchive().chain((_id) { | 69 return _createArchive().chain((_id) { |
| 70 id = _id; | 70 id = _id; |
| 71 return call(OPEN_MEMORY, id, [bytesForC(data)]); | 71 return call(OPEN_MEMORY, id, [bytesForC(data)]); |
| 72 }).transform((_) => new ArchiveInputStream(id)); | 72 }).then((_) => new ArchiveInputStream(id)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * Creates an archive struct, applies all the configuration options to it, and | 76 * Creates an archive struct, applies all the configuration options to it, and |
| 77 * returns its id. | 77 * returns its id. |
| 78 */ | 78 */ |
| 79 Future<int> _createArchive() { | 79 Future<int> _createArchive() { |
| 80 return call(NEW).chain((id) { | 80 return call(NEW).chain((id) { |
| 81 if (id == 0 || id == null) { | 81 if (id == 0 || id == null) { |
| 82 throw new ArchiveException("Archive is invalid or closed."); | 82 throw new ArchiveException("Archive is invalid or closed."); |
| 83 } | 83 } |
| 84 return _pushConfiguration(id).transform((_) => id); | 84 return _pushConfiguration(id).then((_) => id); |
| 85 }); | 85 }); |
| 86 } | 86 } |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * Applies all configuration in this archive to the archive identified by | 89 * Applies all configuration in this archive to the archive identified by |
| 90 * [id]. Returns a future that completes once all the configuration is | 90 * [id]. Returns a future that completes once all the configuration is |
| 91 * applied. | 91 * applied. |
| 92 */ | 92 */ |
| 93 Future _pushConfiguration(int id) { | 93 Future _pushConfiguration(int id) { |
| 94 var pending = <Future>[]; | 94 var pending = <Future>[]; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 /** | 290 /** |
| 291 * Options for individual formats. See [the libarchive documentation][wiki] | 291 * Options for individual formats. See [the libarchive documentation][wiki] |
| 292 * for a list of available options. | 292 * for a list of available options. |
| 293 * | 293 * |
| 294 * [wiki]: https://github.com/libarchive/libarchive/wiki/ManPageArchiveReadSet
Options3 | 294 * [wiki]: https://github.com/libarchive/libarchive/wiki/ManPageArchiveReadSet
Options3 |
| 295 */ | 295 */ |
| 296 final ArchiveOptions options; | 296 final ArchiveOptions options; |
| 297 | 297 |
| 298 Format._() : options = new ArchiveOptions(); | 298 Format._() : options = new ArchiveOptions(); |
| 299 } | 299 } |
| OLD | NEW |