readFile method

Future<Uint8List> readFile(
  1. String path
)

Reads a file from the Frame device.

Args: path (String): The full filename to read on the Frame.

Returns: Future

Raises: Exception: If the file does not exist.

Implementation

Future<Uint8List> readFile(String path) async {
  if (!frame.useLibrary) {
    throw Exception("Cannot read file via SDK without library helpers");
  }
  frame.bluetooth.sendString('printCompleteFile("$path")');
  final Uint8List result = await frame.bluetooth.waitForData();
  // remove any trailing newlines if there are any
  final lengthToRemove = result.lastIndexOf(10);
  if (lengthToRemove != -1) {
    return result.sublist(0, lengthToRemove);
  }
  return result;
}