Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Unified Diff: pkg/front_end/lib/physical_file_system.dart

Issue 2471283002: Add implementations of the front end FileSystem API. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/lib/physical_file_system.dart
diff --git a/pkg/front_end/lib/physical_file_system.dart b/pkg/front_end/lib/physical_file_system.dart
new file mode 100644
index 0000000000000000000000000000000000000000..03a523fe6f9100a0fd5e543d063b127294a15079
--- /dev/null
+++ b/pkg/front_end/lib/physical_file_system.dart
@@ -0,0 +1,57 @@
+// Copyright (c) 2016, 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 front_end.physical_file_system;
+
+import 'dart:async';
+import 'dart:io' as io;
+
+import 'package:path/path.dart' as p;
+
+import 'file_system.dart';
+
+/// Concrete implementation of [FileSystem] which performs its operations using
+/// I/O.
+///
+/// Not intended to be implemented or extended by clients.
+class PhysicalFileSystem implements FileSystem {
+ static PhysicalFileSystem instance = new PhysicalFileSystem._();
scheglov 2016/11/03 02:15:24 +final?
Paul Berry 2016/11/03 15:16:41 Done. Thank you.
+
+ PhysicalFileSystem._();
+
+ @override
+ p.Context get context => p.context;
+
+ @override
+ FileSystemEntity entityForPath(String path) =>
+ new _PhysicalFileSystemEntity(context.normalize(context.absolute(path)));
+
+ @override
+ FileSystemEntity entityForUri(Uri uri) {
+ if (uri.scheme != 'file') throw new ArgumentError('File URI expected');
+ return entityForPath(context.fromUri(uri));
+ }
+}
+
+/// Concrete implementation of [FileSystemEntity] for use by
+/// [PhysicalFileSystem].
+class _PhysicalFileSystemEntity implements FileSystemEntity {
+ @override
+ final String path;
+
+ _PhysicalFileSystemEntity(this.path);
+
+ @override
+ int get hashCode => path.hashCode;
+
+ @override
+ bool operator ==(Object other) =>
+ other is _PhysicalFileSystemEntity && other.path == path;
+
+ @override
+ Future<List<int>> readAsBytes() => new io.File(path).readAsBytes();
+
+ @override
+ Future<String> readAsString() => new io.File(path).readAsString();
+}

Powered by Google App Engine
This is Rietveld 408576698