| Index: utils/tests/pub/descriptor/tar.dart
|
| diff --git a/utils/tests/pub/descriptor/tar.dart b/utils/tests/pub/descriptor/tar.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ef9b1f320dfef4a2f780fa213dca16f33cb84e95
|
| --- /dev/null
|
| +++ b/utils/tests/pub/descriptor/tar.dart
|
| @@ -0,0 +1,53 @@
|
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +library descriptor.tar;
|
| +
|
| +import 'dart:io';
|
| +import 'dart:async';
|
| +
|
| +import '../../../../pkg/pathos/lib/path.dart' as path;
|
| +import '../../../../pkg/scheduled_test/lib/scheduled_test.dart';
|
| +import '../../../../pkg/scheduled_test/lib/descriptor.dart';
|
| +
|
| +import '../../../pub/io.dart';
|
| +import '../../../pub/utils.dart';
|
| +
|
| +/// Describes a tar file and its contents.
|
| +class TarFileDescriptor extends DirectoryDescriptor {
|
| + TarFileDescriptor(String name, List<Descriptor> contents)
|
| + : super(name, contents);
|
| +
|
| + /// Creates the files and directories within this tar file, then archives
|
| + /// them, compresses them, and saves the result to [parentDir].
|
| + Future<String> create([String parent]) => schedule(() {
|
| + if (parent == null) parent = defaultRoot;
|
| + return withTempDir((tempDir) {
|
| + return Future.wait(contents.map((entry) {
|
| + return entry.create(tempDir);
|
| + })).then((_) {
|
| + return listDir(tempDir, recursive: true, includeHiddenFiles: true);
|
| + }).then((createdContents) {
|
| + return createTarGz(createdContents, baseDir: tempDir).toBytes();
|
| + }).then((bytes) {
|
| + var file = path.join(parent, name);
|
| + writeBinaryFile(file, bytes);
|
| + return file;
|
| + });
|
| + });
|
| + }, 'creating tar file:\n${describe()}');
|
| +
|
| + /// Validates that the `.tar.gz` file at [path] contains the expected
|
| + /// contents.
|
| + Future validate([String parent]) {
|
| + throw "TODO(nweiz): implement this";
|
| + }
|
| +
|
| + Stream<List<int>> read() {
|
| + return new Stream<List<int>>.fromFuture(withTempDir((tempDir) {
|
| + return create(tempDir).then((_) =>
|
| + readBinaryFile(path.join(tempDir, name)));
|
| + }));
|
| + }
|
| +}
|
|
|