download method
This is an advanced method of Televerse. This method downloads the
particular file and saves it to the specified path.
Specify the token parameter if you want to use a specific bot token.
Note: Make sure the path is a valid path and the directory exists.
Implementation
Future<io.File?> download({String? path, String? token}) async {
path ??= io.Directory.current.path;
String fpath;
final name = filePath?.split("/").last;
final ext = name?.split(".").last;
final bytes = await getBytes(token);
if (bytes == null) return null;
if (path.endsWith(".$ext")) {
fpath = path;
} else {
fpath = "$path/$name";
}
final file = io.File(fpath);
if (!file.existsSync()) {
file.createSync();
}
return await file.writeAsBytes(bytes);
}