Commit a local file system, some updates.
diff --git a/lib/file.dart b/lib/file.dart
new file mode 100644
index 0000000..74bb212
--- /dev/null
+++ b/lib/file.dart
@@ -0,0 +1,4 @@
+library file;
+
+export 'package:file/src/backends/in_memory.dart';
+export 'package:file/src/interface.dart';
diff --git a/lib/io.dart b/lib/io.dart
new file mode 100644
index 0000000..4921c6a
--- /dev/null
+++ b/lib/io.dart
@@ -0,0 +1,4 @@
+library file.io;
+
+export 'package:file/src/backends/local.dart';
+export 'package:file/file.dart';
diff --git a/lib/src/backends/in_memory/in_memory_directory.dart b/lib/src/backends/in_memory/in_memory_directory.dart
index bb0576a..078086d 100644
--- a/lib/src/backends/in_memory/in_memory_directory.dart
+++ b/lib/src/backends/in_memory/in_memory_directory.dart
@@ -16,7 +16,7 @@
throw new FileSystemEntityException('Not found', path);
}
if (name != '') {
- directory = directory[name];
+ directory = directory[name] as Map<String, Object>;
}
// This could be optimized heavily, right now it makes a lot of extra
// lookups and gets more and more expensive as you traverse downwards.
diff --git a/lib/src/backends/in_memory/in_memory_file_system_entity.dart b/lib/src/backends/in_memory/in_memory_file_system_entity.dart
index 9da753e..55cc589 100644
--- a/lib/src/backends/in_memory/in_memory_file_system_entity.dart
+++ b/lib/src/backends/in_memory/in_memory_file_system_entity.dart
@@ -21,7 +21,7 @@
var reference = _resolve(true, newPath);
Object clone = parent[name];
if (clone is! String) {
- clone = _cloneSafe(clone);
+ clone = _cloneSafe(clone as Map<String, Object>);
}
reference[newPath.substring(newPath.lastIndexOf('/') + 1)] = clone;
if (_type == FileSystemEntityType.FILE) {
diff --git a/lib/src/backends/local.dart b/lib/src/backends/local.dart
new file mode 100644
index 0000000..f261831
--- /dev/null
+++ b/lib/src/backends/local.dart
@@ -0,0 +1,11 @@
+library file.src.backends.local;
+
+import 'dart:async';
+import 'dart:io' as io;
+
+import 'package:file/src/interface.dart';
+
+part 'local/local_directory.dart';
+part 'local/local_file.dart';
+part 'local/local_file_system.dart';
+part 'local/local_file_system_entity.dart';
diff --git a/lib/src/backends/local/local_directory.dart b/lib/src/backends/local/local_directory.dart
new file mode 100644
index 0000000..4a3a60b
--- /dev/null
+++ b/lib/src/backends/local/local_directory.dart
@@ -0,0 +1,32 @@
+part of file.src.backends.local;
+
+class _LocalDirectory extends _LocalFileSystemEntity implements Directory {
+ _LocalDirectory(io.Directory entity, FileSystem system) : super(entity, system);
+
+ @override
+ Future<Directory> copy(String newPath) async {
+ throw new UnsupportedError('Not a supported operation');
+ }
+
+ @override
+ Future<Directory> create({bool recursive: false}) async {
+ return new _LocalDirectory(
+ await (_ioEntity as io.Directory).create(recursive: recursive),
+ fileSystem);
+ }
+
+ @override
+ Stream<FileSystemEntity> list({bool recursive: false}) {
+ return (_ioEntity as io.Directory)
+ .list(recursive: recursive)
+ .map((ioEntity) {
+ if (ioEntity is io.File) {
+ return new _LocalFile(ioEntity, fileSystem);
+ }
+ if (ioEntity is io.Directory) {
+ return new _LocalDirectory(ioEntity, fileSystem);
+ }
+ return null;
+ }).where((e) => e != null) as Stream<FileSystemEntity>;
+ }
+}
diff --git a/lib/src/backends/local/local_file.dart b/lib/src/backends/local/local_file.dart
new file mode 100644
index 0000000..6d4d87e
--- /dev/null
+++ b/lib/src/backends/local/local_file.dart
@@ -0,0 +1,19 @@
+part of file.src.backends.local;
+
+class _LocalFile extends _LocalFileSystemEntity implements File {
+ _LocalFile(io.File entity, FileSystem system) : super(entity, system);
+
+ @override
+ Future<File> copy(String newPath) async {
+ return new _LocalFile(
+ await (_ioEntity as io.File).copy(newPath),
+ fileSystem);
+ }
+
+ @override
+ Future<File> create({bool recursive: false}) async {
+ return new _LocalFile(
+ await (_ioEntity as io.File).create(recursive: recursive),
+ fileSystem);
+ }
+}
diff --git a/lib/src/backends/local/local_file_system.dart b/lib/src/backends/local/local_file_system.dart
new file mode 100644
index 0000000..132fe5e
--- /dev/null
+++ b/lib/src/backends/local/local_file_system.dart
@@ -0,0 +1,24 @@
+part of file.src.backends.local;
+
+/// A wrapper implementation around `dart:io`'s implementation.
+class LocalFileSystem implements FileSystem {
+ const LocalFileSystem();
+
+ @override
+ Directory directory(String path) => new _LocalDirectory(new io.Directory(path), this);
+
+ @override
+ File file(String path) => new _LocalFile(new io.File(path), this);
+
+ @override
+ Future<FileSystemEntityType> type(String path, {bool followLinks: true}) async {
+ var type = await io.FileSystemEntity.type(path);
+ if (type == io.FileSystemEntityType.FILE) {
+ return FileSystemEntityType.FILE;
+ } else if (type == io.FileSystemEntityType.DIRECTORY) {
+ return FileSystemEntityType.DIRECTORY;
+ } else {
+ return FileSystemEntityType.NOT_FOUND;
+ }
+ }
+}
diff --git a/lib/src/backends/local/local_file_system_entity.dart b/lib/src/backends/local/local_file_system_entity.dart
new file mode 100644
index 0000000..e1dd6db
--- /dev/null
+++ b/lib/src/backends/local/local_file_system_entity.dart
@@ -0,0 +1,31 @@
+part of file.src.backends.local;
+
+abstract class _LocalFileSystemEntity implements FileSystemEntity {
+ @override
+ final FileSystem fileSystem;
+
+ io.FileSystemEntity _ioEntity;
+
+ _LocalFileSystemEntity(this._ioEntity, this.fileSystem);
+
+ @override
+ Future<FileSystemEntity> delete({bool recursive: false}) async {
+ await _ioEntity.delete(recursive: recursive);
+ return this;
+ }
+
+ @override
+ Future<bool> exists() => _ioEntity.exists();
+
+ @override
+ Directory get parent => new _LocalDirectory(_ioEntity.parent, fileSystem);
+
+ @override
+ String get path => _ioEntity.path;
+
+ @override
+ Future<FileSystemEntity> rename(String newPath) async {
+ _ioEntity = await _ioEntity.rename(newPath);
+ return this;
+ }
+}