getBytes method

Future<Uint8List?> getBytes([
  1. String? token
])

This is an advanced method in Televerse. This returns Uint8List? representing the byte data of the file.

This method basically gets the file and decodes it's byte data. This can be very useful if you want to download the file or save it.

Use the token parameter to specify the bot token to be used - if you're running multiple bots with the same code.

Implementation

Future<Uint8List?> getBytes([String? token]) async {
  try {
    final dio = Dio();
    final r = await dio.getUri(
      getDownloadURI(token),
      options: Options(responseType: ResponseType.bytes),
    );
    dio.close();
    if (r.statusCode == 200) {
      return r.data as Uint8List;
    } else {
      throw TeleverseException(
        "Couldn't fetch the file data.",
        description:
            "The request to fetch the file data failed with status code ${r.statusCode}.",
        type: TeleverseExceptionType.requestFailed,
      );
    }
  } catch (err) {
    return null;
  }
}