Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016, 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 library front_end.physical_file_system; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:io' as io; | |
| 9 | |
| 10 import 'package:path/path.dart' as p; | |
| 11 | |
| 12 import 'file_system.dart'; | |
| 13 | |
| 14 /// Concrete implementation of [FileSystem] which performs its operations using | |
| 15 /// I/O. | |
| 16 /// | |
| 17 /// Not intended to be implemented or extended by clients. | |
| 18 class PhysicalFileSystem implements FileSystem { | |
| 19 static PhysicalFileSystem instance = new PhysicalFileSystem._(); | |
|
scheglov
2016/11/03 02:15:24
+final?
Paul Berry
2016/11/03 15:16:41
Done. Thank you.
| |
| 20 | |
| 21 PhysicalFileSystem._(); | |
| 22 | |
| 23 @override | |
| 24 p.Context get context => p.context; | |
| 25 | |
| 26 @override | |
| 27 FileSystemEntity entityForPath(String path) => | |
| 28 new _PhysicalFileSystemEntity(context.normalize(context.absolute(path))); | |
| 29 | |
| 30 @override | |
| 31 FileSystemEntity entityForUri(Uri uri) { | |
| 32 if (uri.scheme != 'file') throw new ArgumentError('File URI expected'); | |
| 33 return entityForPath(context.fromUri(uri)); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 /// Concrete implementation of [FileSystemEntity] for use by | |
| 38 /// [PhysicalFileSystem]. | |
| 39 class _PhysicalFileSystemEntity implements FileSystemEntity { | |
| 40 @override | |
| 41 final String path; | |
| 42 | |
| 43 _PhysicalFileSystemEntity(this.path); | |
| 44 | |
| 45 @override | |
| 46 int get hashCode => path.hashCode; | |
| 47 | |
| 48 @override | |
| 49 bool operator ==(Object other) => | |
| 50 other is _PhysicalFileSystemEntity && other.path == path; | |
| 51 | |
| 52 @override | |
| 53 Future<List<int>> readAsBytes() => new io.File(path).readAsBytes(); | |
| 54 | |
| 55 @override | |
| 56 Future<String> readAsString() => new io.File(path).readAsString(); | |
| 57 } | |
| OLD | NEW |