OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 descriptor.tar; | 5 library descriptor.tar; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 | 9 |
10 import 'package:pathos/path.dart' as path; | 10 import 'package:pathos/path.dart' as path; |
11 import 'package:scheduled_test/scheduled_test.dart'; | 11 import 'package:scheduled_test/scheduled_test.dart'; |
12 import 'package:scheduled_test/descriptor.dart'; | 12 import 'package:scheduled_test/descriptor.dart'; |
13 | 13 |
14 import '../../../pub/io.dart'; | 14 import '../../../pub/io.dart'; |
15 import '../../../pub/utils.dart'; | 15 import '../../../pub/utils.dart'; |
16 | 16 |
17 /// Describes a tar file and its contents. | 17 /// Describes a tar file and its contents. |
18 class TarFileDescriptor extends DirectoryDescriptor { | 18 class TarFileDescriptor extends DirectoryDescriptor { |
19 TarFileDescriptor(String name, List<Descriptor> contents) | 19 TarFileDescriptor(String name, List<Descriptor> contents) |
20 : super(name, contents); | 20 : super(name, contents); |
21 | 21 |
22 /// Creates the files and directories within this tar file, then archives | 22 /// Creates the files and directories within this tar file, then archives |
23 /// them, compresses them, and saves the result to [parentDir]. | 23 /// them, compresses them, and saves the result to [parentDir]. |
24 Future<String> create([String parent]) => schedule(() { | 24 Future<String> create([String parent]) => schedule(() { |
25 if (parent == null) parent = defaultRoot; | 25 if (parent == null) parent = defaultRoot; |
26 return withTempDir((tempDir) { | 26 return withTempDir((tempDir) { |
27 return Future.wait(contents.map((entry) { | 27 return Future.wait(contents.map((entry) { |
28 return entry.create(tempDir); | 28 return entry.create(tempDir); |
29 })).then((_) { | 29 })).then((_) { |
30 return listDir(tempDir, recursive: true, includeHiddenFiles: true); | 30 var createdContents = listDir(tempDir, |
31 }).then((createdContents) { | 31 recursive: true, |
| 32 includeHiddenFiles: true); |
32 return createTarGz(createdContents, baseDir: tempDir).toBytes(); | 33 return createTarGz(createdContents, baseDir: tempDir).toBytes(); |
33 }).then((bytes) { | 34 }).then((bytes) { |
34 var file = path.join(parent, name); | 35 var file = path.join(parent, name); |
35 writeBinaryFile(file, bytes); | 36 writeBinaryFile(file, bytes); |
36 return file; | 37 return file; |
37 }); | 38 }); |
38 }); | 39 }); |
39 }, 'creating tar file:\n${describe()}'); | 40 }, 'creating tar file:\n${describe()}'); |
40 | 41 |
41 /// Validates that the `.tar.gz` file at [path] contains the expected | 42 /// Validates that the `.tar.gz` file at [path] contains the expected |
42 /// contents. | 43 /// contents. |
43 Future validate([String parent]) { | 44 Future validate([String parent]) { |
44 throw "TODO(nweiz): implement this"; | 45 throw "TODO(nweiz): implement this"; |
45 } | 46 } |
46 | 47 |
47 Stream<List<int>> read() { | 48 Stream<List<int>> read() { |
48 return new Stream<List<int>>.fromFuture(withTempDir((tempDir) { | 49 return new Stream<List<int>>.fromFuture(withTempDir((tempDir) { |
49 return create(tempDir).then((_) => | 50 return create(tempDir).then((_) => |
50 readBinaryFile(path.join(tempDir, name))); | 51 readBinaryFile(path.join(tempDir, name))); |
51 })); | 52 })); |
52 } | 53 } |
53 } | 54 } |
OLD | NEW |