-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdcc_file_store_io.dart
More file actions
44 lines (35 loc) · 1.08 KB
/
dcc_file_store_io.dart
File metadata and controls
44 lines (35 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import 'dart:io';
import 'dcc_file_store.dart';
class _IoDccFileSink implements DccFileSink {
_IoDccFileSink(this._sink);
final IOSink _sink;
@override
void add(List<int> bytes) {
_sink.add(bytes);
}
@override
Future<void> close() => _sink.close();
@override
Future<void> flush() => _sink.flush();
}
Future<DccTempFile> createPlatformDccTempFile(String fileName) async {
final sanitized = fileName.replaceAll(RegExp(r'[\\/:*?"<>|]'), '_');
final path = '${Directory.systemTemp.path}/$sanitized';
final file = File(path);
final sink = file.openWrite(mode: FileMode.writeOnly);
return (path: path, sink: _IoDccFileSink(sink));
}
Future<DccSourceFile> openPlatformDccSourceFile(String path) async {
final file = File(path);
final exists = await file.exists();
if (!exists) {
throw FileSystemException('DCC source file does not exist.', path);
}
final stat = await file.stat();
return (
path: file.path,
fileName: file.uri.pathSegments.isEmpty ? file.path : file.uri.pathSegments.last,
size: stat.size,
readAllBytes: file.readAsBytes,
);
}