OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 /// A memory + physical file system used to mock input for tests but provide | |
6 /// sdk sources from disk. | |
7 library front_end.src.hybrid_file_system; | |
Siggi Cherem (dart-lang)
2017/06/06 22:22:29
FYI - this code is the same as before (moved from
ahe
2017/06/07 10:28:59
If this is used or intended for anything else but
| |
8 | |
9 import 'dart:async'; | |
10 | |
11 import 'package:front_end/file_system.dart'; | |
12 import 'package:front_end/memory_file_system.dart'; | |
13 import 'package:front_end/physical_file_system.dart'; | |
14 | |
15 /// A file system that mixes files from memory and a physical file system. All | |
16 /// memory entities take priotity over file system entities. | |
17 class HybridFileSystem implements FileSystem { | |
18 final MemoryFileSystem memory; | |
19 final PhysicalFileSystem physical = PhysicalFileSystem.instance; | |
20 | |
21 HybridFileSystem(this.memory); | |
22 | |
23 @override | |
24 FileSystemEntity entityForUri(Uri uri) => new HybridFileSystemEntity( | |
25 memory.entityForUri(uri), physical.entityForUri(uri)); | |
26 } | |
27 | |
28 /// Entity that delegates to an underlying memory or phisical file system | |
29 /// entity. | |
30 class HybridFileSystemEntity implements FileSystemEntity { | |
31 final FileSystemEntity memory; | |
32 final FileSystemEntity physical; | |
33 | |
34 HybridFileSystemEntity(this.memory, this.physical); | |
35 | |
36 FileSystemEntity _delegate; | |
37 Future<FileSystemEntity> get delegate async { | |
38 return _delegate ??= (await memory.exists()) ? memory : physical; | |
39 } | |
40 | |
41 @override | |
42 Uri get uri => memory.uri; | |
43 | |
44 @override | |
45 Future<bool> exists() async => (await delegate).exists(); | |
46 | |
47 @override | |
48 Future<DateTime> lastModified() async => (await delegate).lastModified(); | |
49 | |
50 @override | |
51 Future<List<int>> readAsBytes() async => (await delegate).readAsBytes(); | |
52 | |
53 @override | |
54 Future<String> readAsString() async => (await delegate).readAsString(); | |
55 } | |
OLD | NEW |