installBinaryToTempDir function

String installBinaryToTempDir(
  1. Uint8List bytes, {
  2. String prefix = '',
  3. dynamic suffix = '',
  4. int trial = 0,
})

Installs bytes to temp dir and returns the full path of that file

Implementation

String installBinaryToTempDir(
  Uint8List bytes, {
  String prefix = '',
  suffix = '',
  int trial = 0,
}) {
  var sha = md5(bytes);
  String fileName = prefix + sha + (trial == 0 ? '' : '_$trial') + suffix;
  String path = path_path.join(pathOfTempDir, fileName).replaceAll(r'\', '/');
  if (!fileExists(path)) {
    String uuid = uuidTimeBased();
    writeFileBytes('$path.$uuid', bytes);
    try {
      //dart_io.File('$path.$uuid').renameSync(path);
      pathRename('$path.$uuid', path);
    } catch (_) {}
  }
  Uint8List bytes2 = readFileBytes(path);
  if (identicalBinaries(bytes, bytes2)) {
    return path;
  }
  return installBinaryToTempDir(
    bytes,
    prefix: prefix,
    suffix: suffix,
    trial: trial + 1,
  );
}