|
1 | | -import 'dart:io'; |
2 | | -import 'dart:typed_data'; |
3 | | - |
4 | 1 | import '../random_access_source.dart'; |
| 2 | +import 'file_ra_source_stub.dart' |
| 3 | + if (dart.library.io) 'file_ra_source_vm.dart' |
| 4 | + if (dart.library.js_interop) 'file_ra_source_web.dart' as impl; |
5 | 5 |
|
6 | | -class FileRASource extends RandomAccessSource { |
7 | | - final RandomAccessFile _file; |
8 | | - |
9 | | - FileRASource(this._file); |
10 | | - |
11 | | - static Future<FileRASource> open(String path) async { |
12 | | - final file = await File(path).open(); |
13 | | - return FileRASource(file); |
14 | | - } |
15 | | - |
16 | | - @override |
17 | | - Future<int> length() async { |
18 | | - return _file.length(); |
19 | | - } |
20 | | - |
21 | | - @override |
22 | | - Future<int> readByte() async { |
23 | | - return _file.readByte(); |
24 | | - } |
25 | | - |
26 | | - @override |
27 | | - Future<Uint8List> read(int count) async { |
28 | | - return _file.read(count); |
29 | | - } |
30 | | - |
31 | | - @override |
32 | | - Future<int> position() async { |
33 | | - return _file.position(); |
34 | | - } |
35 | | - |
36 | | - @override |
37 | | - Future<void> seek(int position) async { |
38 | | - await _file.setPosition(position); |
39 | | - } |
| 6 | +typedef PlatformFile = impl.PlatformFile; |
40 | 7 |
|
41 | | - @override |
42 | | - Future<Uint8List> readToEnd() async { |
43 | | - return _file.read(await _file.length()); |
44 | | - } |
| 8 | +abstract class FileRASource extends RandomAccessSource { |
| 9 | + static Future<FileRASource> open(String path) => impl.FileRASource.open(path); |
45 | 10 |
|
46 | | - @override |
47 | | - Future<void> close() async { |
48 | | - await _file.close(); |
49 | | - } |
| 11 | + static Future<FileRASource> load(PlatformFile file) => |
| 12 | + impl.FileRASource.load(file); |
50 | 13 | } |
0 commit comments