Line data Source code
1 : import 'package:flutter/foundation.dart';
2 : import '../worker.dart';
3 :
4 : /// File system operations.
5 : enum FileOperation {
6 : copy('copy'),
7 : move('move'),
8 : delete('delete'),
9 : mkdir('mkdir'),
10 : list('list');
11 :
12 : const FileOperation(this.value);
13 : final String value;
14 : }
15 :
16 : /// File system worker configuration for copy operation.
17 : @immutable
18 : final class FileSystemCopyWorker extends Worker {
19 3 : const FileSystemCopyWorker({
20 : required this.sourcePath,
21 : required this.destinationPath,
22 : this.overwrite = false,
23 : this.recursive = true,
24 6 : }) : assert(sourcePath != '', 'sourcePath must not be empty'),
25 6 : assert(destinationPath != '', 'destinationPath must not be empty');
26 :
27 : final String sourcePath;
28 : final String destinationPath;
29 : final bool overwrite;
30 : final bool recursive;
31 :
32 3 : @override
33 : String get workerClassName => 'FileSystemWorker';
34 :
35 3 : @override
36 3 : Map<String, dynamic> toMap() => {
37 : 'workerType': 'fileSystem',
38 : 'operation': 'copy',
39 3 : 'sourcePath': sourcePath,
40 3 : 'destinationPath': destinationPath,
41 3 : 'overwrite': overwrite,
42 3 : 'recursive': recursive,
43 : };
44 : }
45 :
46 : /// File system worker configuration for move operation.
47 : @immutable
48 : final class FileSystemMoveWorker extends Worker {
49 3 : const FileSystemMoveWorker({
50 : required this.sourcePath,
51 : required this.destinationPath,
52 : this.overwrite = false,
53 6 : }) : assert(sourcePath != '', 'sourcePath must not be empty'),
54 6 : assert(destinationPath != '', 'destinationPath must not be empty');
55 :
56 : final String sourcePath;
57 : final String destinationPath;
58 : final bool overwrite;
59 :
60 3 : @override
61 : String get workerClassName => 'FileSystemWorker';
62 :
63 3 : @override
64 3 : Map<String, dynamic> toMap() => {
65 : 'workerType': 'fileSystem',
66 : 'operation': 'move',
67 3 : 'sourcePath': sourcePath,
68 3 : 'destinationPath': destinationPath,
69 3 : 'overwrite': overwrite,
70 : };
71 : }
72 :
73 : /// File system worker configuration for delete operation.
74 : @immutable
75 : final class FileSystemDeleteWorker extends Worker {
76 3 : const FileSystemDeleteWorker({
77 : required this.path,
78 : this.recursive = false,
79 6 : }) : assert(path != '', 'path must not be empty');
80 :
81 : final String path;
82 : final bool recursive;
83 :
84 3 : @override
85 : String get workerClassName => 'FileSystemWorker';
86 :
87 3 : @override
88 3 : Map<String, dynamic> toMap() => {
89 : 'workerType': 'fileSystem',
90 : 'operation': 'delete',
91 3 : 'path': path,
92 3 : 'recursive': recursive,
93 : };
94 : }
95 :
96 : /// File system worker configuration for list operation.
97 : @immutable
98 : final class FileSystemListWorker extends Worker {
99 3 : const FileSystemListWorker({
100 : required this.path,
101 : this.pattern,
102 : this.recursive = false,
103 6 : }) : assert(path != '', 'path must not be empty');
104 :
105 : final String path;
106 : final String? pattern;
107 : final bool recursive;
108 :
109 2 : @override
110 : String get workerClassName => 'FileSystemWorker';
111 :
112 3 : @override
113 3 : Map<String, dynamic> toMap() => {
114 3 : 'workerType': 'fileSystem',
115 3 : 'operation': 'list',
116 6 : 'path': path,
117 9 : if (pattern != null) 'pattern': pattern,
118 6 : 'recursive': recursive,
119 : };
120 : }
121 :
122 : /// File system worker configuration for mkdir operation.
123 : @immutable
124 : final class FileSystemMkdirWorker extends Worker {
125 3 : const FileSystemMkdirWorker({
126 : required this.path,
127 : this.createParents = true,
128 6 : }) : assert(path != '', 'path must not be empty');
129 :
130 : final String path;
131 : final bool createParents;
132 :
133 2 : @override
134 : String get workerClassName => 'FileSystemWorker';
135 :
136 3 : @override
137 3 : Map<String, dynamic> toMap() => {
138 : 'workerType': 'fileSystem',
139 : 'operation': 'mkdir',
140 3 : 'path': path,
141 3 : 'createParents': createParents,
142 : };
143 : }
|