writeBinary method
Write a binary stream to a file.
Creates the parent directory if necessary.
If makeExecutable
is set to true
, this method attempts to make this
File executable. This currently only works on Linux and MacOS.
Implementation
Future<File> writeBinary(
Stream<List<int>> stream, {
bool makeExecutable = false,
}) async {
await parent.create(recursive: true);
final handle = openWrite();
try {
await handle.addStream(stream);
await handle.flush();
} finally {
await handle.close();
}
if (makeExecutable && (Platform.isLinux || Platform.isMacOS)) {
final exitCode = await execProc(
Process.start('chmod', ['+x', path], runInShell: true));
if (exitCode != 0) {
throw DartleException(message: 'Unable to make file $path executable');
}
}
return this;
}