saveBytesToFile static method

Future<void> saveBytesToFile(
  1. Uint8List bytes,
  2. String path
)

Save the given bytes to a file at path.

Implementation

static Future<void> saveBytesToFile(Uint8List bytes, String path) async {
  if (bytes.isEmpty) {
    return;
  }

  final receivePort = ReceivePort();
  final transferable = TransferableTypedData.fromList([bytes]);

  await Isolate.spawn(_saveBytesIsolateEntry, [
    receivePort.sendPort,
    path,
    transferable,
  ]);

  final result = await receivePort.first;

  receivePort.close();

  if (result is Exception) {
    throw result;
  }
}