import 'dart:io';
import 'dart:typed_data';
import 'package:path_provider/path_provider.dart';
import 'package:open_filex/open_filex.dart';
Future<void> openManagedBytes(Uint8List bytes, String name, String account) async {
  final root = await getTemporaryDirectory();
  final dir = Directory('${root.path}/rvu_files_$account');
  await dir.create(recursive: true);
  final safe = name.replaceAll(RegExp(r'[^a-zA-Z0-9._ -]'), '_');
  final file = File('${dir.path}/$safe');
  await file.writeAsBytes(bytes, flush: true);
  final result = await OpenFilex.open(file.path);
  if (result.type != ResultType.done) throw StateError(result.message);
}
Future<void> clearManagedExports(String account) async {
  final root = await getTemporaryDirectory();
  final dir = Directory('${root.path}/rvu_files_$account');
  if (await dir.exists()) await dir.delete(recursive: true);
}
