|
| 1 | +import 'src/rust/frb_generated.dart'; |
| 2 | +import 'src/rust/api/opendal_api.dart'; |
| 3 | + |
| 4 | +class FileManager { |
| 5 | + final Operator _operator; |
| 6 | + |
| 7 | + FileManager._(this._operator); |
| 8 | + |
| 9 | + static FileManager initOp( |
| 10 | + {required String schemeStr, required Map<String, String> map}) { |
| 11 | + return FileManager._(Operator(schemeStr: schemeStr, map: map)); |
| 12 | + } |
| 13 | + |
| 14 | + File call(String path) { |
| 15 | + return File._(path: path, operator: _operator); |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +class DirectoryManager { |
| 20 | + final Operator _operator; |
| 21 | + |
| 22 | + DirectoryManager._(this._operator); |
| 23 | + |
| 24 | + static DirectoryManager initOp( |
| 25 | + {required String schemeStr, required Map<String, String> map}) { |
| 26 | + return DirectoryManager._(Operator(schemeStr: schemeStr, map: map)); |
| 27 | + } |
| 28 | + |
| 29 | + Directory call(String path) { |
| 30 | + return Directory._(path: path, operator: _operator); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +class File { |
| 35 | + final String path; |
| 36 | + final Operator _operator; |
| 37 | + |
| 38 | + File._({required this.path, required Operator operator}) |
| 39 | + : _operator = operator; |
| 40 | + |
| 41 | + Future<bool> exists() { |
| 42 | + return _operator.isExist(path: path); |
| 43 | + } |
| 44 | + |
| 45 | + bool existsSync() { |
| 46 | + return _operator.isExistSync(path: path); |
| 47 | + } |
| 48 | + |
| 49 | + Future<Metadata> stat() { |
| 50 | + return _operator.stat(path: path); |
| 51 | + } |
| 52 | + |
| 53 | + Metadata statSync() { |
| 54 | + return _operator.statSync(path: path); |
| 55 | + } |
| 56 | + |
| 57 | + Future<void> delete() { |
| 58 | + return _operator.delete(path: path); |
| 59 | + } |
| 60 | + |
| 61 | + Future<void> rename(String newPath) { |
| 62 | + return _operator.rename(from: path, to: newPath); |
| 63 | + } |
| 64 | + |
| 65 | + void renameSync(String newPath) { |
| 66 | + _operator.renameSync(from: path, to: newPath); |
| 67 | + } |
| 68 | + |
| 69 | + void deleteSync() { |
| 70 | + _operator.deleteSync(path: path); |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +class Directory { |
| 75 | + final String path; |
| 76 | + final Operator _operator; |
| 77 | + |
| 78 | + Directory._({required this.path, required Operator operator}) |
| 79 | + : _operator = operator; |
| 80 | + |
| 81 | + Future<void> create() { |
| 82 | + return _operator.createDir(path: path); |
| 83 | + } |
| 84 | + |
| 85 | + void createSync() { |
| 86 | + _operator.createDirSync(path: path); |
| 87 | + } |
| 88 | + |
| 89 | + Future<bool> exists() { |
| 90 | + return _operator.isExist(path: path); |
| 91 | + } |
| 92 | + |
| 93 | + bool existsSync() { |
| 94 | + return _operator.isExistSync(path: path); |
| 95 | + } |
| 96 | + |
| 97 | + Future<void> rename(String newPath) { |
| 98 | + return _operator.rename(from: path, to: newPath); |
| 99 | + } |
| 100 | + |
| 101 | + void renameSync(String newPath) { |
| 102 | + _operator.renameSync(from: path, to: newPath); |
| 103 | + } |
| 104 | + |
| 105 | + Future<Metadata> stat() { |
| 106 | + return _operator.stat(path: path); |
| 107 | + } |
| 108 | + |
| 109 | + Metadata statSync() { |
| 110 | + return _operator.statSync(path: path); |
| 111 | + } |
| 112 | + |
| 113 | + Future<void> delete() { |
| 114 | + return _operator.delete(path: path); |
| 115 | + } |
| 116 | + |
| 117 | + void deleteSync() { |
| 118 | + _operator.deleteSync(path: path); |
| 119 | + } |
| 120 | +} |
0 commit comments