downloadData method
Implementation
Future downloadData() async {
File file = await File(localPath).create(recursive: true);
var sendIdTask = sendID();
if (shouldTruncate) {
if (await file.exists()) {
await file.delete(recursive: true);
}
await file.create(recursive: true);
}
var fileWriter = file.openWrite(mode: FileMode.writeOnlyAppend);
await sendIdTask;
await _conn.listen((data) {
fileWriter.add(data);
downBytes += data.length;
}, onDone: () async {
await fileWriter.flush();
await fileWriter.close();
await _conn.close();
assert(downBytes == fileInfo.size.toInt());
}).asFuture();
}