Skip to content

Commit 43a433a

Browse files
update, test stub
1 parent 90b6ded commit 43a433a

3 files changed

Lines changed: 193 additions & 3 deletions

File tree

flutter_cache_manager/lib/src/storage/file_system/file_system_web.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import 'package:file/file.dart' show File;
22
import 'package:file/memory.dart';
33
import 'package:flutter_cache_manager/src/storage/file_system/file_system.dart';
44

5-
// Export web-specific implementations
6-
export 'indexed_db_file.dart';
7-
export 'indexed_db_file_system.dart';
5+
// Web-specific implementations: export on web only, export stubs elsewhere
6+
export 'indexed_db_file_stub.dart'
7+
if (dart.library.js_interop) 'indexed_db_file.dart';
8+
export 'indexed_db_file_system_stub.dart'
9+
if (dart.library.js_interop) 'indexed_db_file_system.dart';
810

911
class MemoryCacheSystem implements FileSystem {
1012
final directory = MemoryFileSystem().systemTempDirectory.createTemp('cache');
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
import 'dart:convert';
2+
import 'dart:typed_data';
3+
4+
import 'package:file/file.dart';
5+
6+
// Non-web stub to satisfy conditional export when js_interop is unavailable
7+
class IndexedDbFile implements File {
8+
IndexedDbFile(String path, String dbName);
9+
10+
@override
11+
File get absolute => this;
12+
13+
@override
14+
Future<File> copy(String newPath) => _unsupported();
15+
16+
@override
17+
File copySync(String newPath) => _throw();
18+
19+
@override
20+
Future<File> create({bool recursive = false, bool exclusive = false}) =>
21+
_unsupported();
22+
23+
@override
24+
void createSync({bool recursive = false, bool exclusive = false}) => _throw();
25+
26+
@override
27+
Future<FileSystemEntity> delete({bool recursive = false}) => _unsupported();
28+
29+
@override
30+
void deleteSync({bool recursive = false}) => _throw();
31+
32+
@override
33+
bool existsSync() => _throw();
34+
35+
@override
36+
Future<bool> exists() => _unsupported();
37+
38+
@override
39+
bool get isAbsolute => true;
40+
41+
@override
42+
RandomAccessFile openSync({FileMode mode = FileMode.read}) => _throw();
43+
44+
@override
45+
Future<RandomAccessFile> open({FileMode mode = FileMode.read}) =>
46+
_unsupported();
47+
48+
@override
49+
Stream<List<int>> openRead([int? start, int? end]) =>
50+
Stream<List<int>>.error(_unsupportedError());
51+
52+
@override
53+
IOSink openWrite(
54+
{FileMode mode = FileMode.write, Encoding encoding = utf8}) =>
55+
_throw();
56+
57+
@override
58+
Directory get parent => _throw();
59+
60+
@override
61+
String get path => _throw();
62+
63+
@override
64+
Future<int> length() => _unsupported();
65+
66+
@override
67+
int lengthSync() => _throw();
68+
69+
@override
70+
Future<Uint8List> readAsBytes() => _unsupported();
71+
72+
@override
73+
Uint8List readAsBytesSync() => _throw();
74+
75+
@override
76+
Future<String> readAsString({Encoding encoding = utf8}) => _unsupported();
77+
78+
@override
79+
String readAsStringSync({Encoding encoding = utf8}) => _throw();
80+
81+
@override
82+
Future<List<String>> readAsLines({Encoding encoding = utf8}) =>
83+
_unsupported();
84+
85+
@override
86+
List<String> readAsLinesSync({Encoding encoding = utf8}) => _throw();
87+
88+
@override
89+
Future<File> rename(String newPath) => _unsupported();
90+
91+
@override
92+
File renameSync(String newPath) => _throw();
93+
94+
@override
95+
Future<String> resolveSymbolicLinks() => _unsupported();
96+
97+
@override
98+
String resolveSymbolicLinksSync() => _throw();
99+
100+
@override
101+
Future<DateTime> lastAccessed() => _unsupported();
102+
103+
@override
104+
DateTime lastAccessedSync() => _throw();
105+
106+
@override
107+
Future<DateTime> lastModified() => _unsupported();
108+
109+
@override
110+
DateTime lastModifiedSync() => _throw();
111+
112+
@override
113+
FileStat statSync() => _throw();
114+
115+
@override
116+
Future<FileStat> stat() => _unsupported();
117+
118+
@override
119+
Uri get uri => _throw();
120+
121+
@override
122+
String get basename => _throw();
123+
124+
@override
125+
String get dirname => _throw();
126+
127+
@override
128+
Stream<FileSystemEvent> watch(
129+
{int events = FileSystemEvent.all, bool recursive = false}) =>
130+
Stream<FileSystemEvent>.error(_unsupportedError());
131+
132+
@override
133+
Future<File> writeAsBytes(List<int> bytes,
134+
{FileMode mode = FileMode.write, bool flush = false}) =>
135+
_unsupported();
136+
137+
@override
138+
void writeAsBytesSync(List<int> bytes,
139+
{FileMode mode = FileMode.write, bool flush = false}) =>
140+
_throw();
141+
142+
@override
143+
Future<File> writeAsString(String contents,
144+
{FileMode mode = FileMode.write,
145+
Encoding encoding = utf8,
146+
bool flush = false}) =>
147+
_unsupported();
148+
149+
@override
150+
void writeAsStringSync(String contents,
151+
{FileMode mode = FileMode.write,
152+
Encoding encoding = utf8,
153+
bool flush = false}) =>
154+
_throw();
155+
156+
@override
157+
void setLastAccessedSync(DateTime time) => _throw();
158+
159+
@override
160+
Future<File> setLastAccessed(DateTime time) => _unsupported();
161+
162+
@override
163+
void setLastModifiedSync(DateTime time) => _throw();
164+
165+
@override
166+
Future<File> setLastModified(DateTime time) => _unsupported();
167+
168+
T _throw<T>() => throw _unsupportedError();
169+
Future<T> _unsupported<T>() => Future<T>.error(_unsupportedError());
170+
UnsupportedError _unsupportedError() =>
171+
UnsupportedError('IndexedDbFile is only available on web');
172+
173+
@override
174+
FileSystem get fileSystem => _throw();
175+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:file/file.dart' as file_pkg;
2+
import 'package:flutter_cache_manager/src/storage/file_system/file_system.dart'
3+
as cache_fs;
4+
5+
// Non-web stub to satisfy conditional export when js_interop is unavailable
6+
class IndexedDbFileSystem implements cache_fs.FileSystem {
7+
IndexedDbFileSystem(String databaseName);
8+
9+
@override
10+
Future<file_pkg.File> createFile(String name) async {
11+
throw UnsupportedError('IndexedDbFileSystem is only available on web');
12+
}
13+
}

0 commit comments

Comments
 (0)