put method
Write the contents of a file.
Implementation
@override
Future<bool> put(
String path,
dynamic contents, {
Map<String, dynamic>? options,
}) async {
try {
final file = fileSystem.file(_getFullPath(path));
// Create parent directories if they don't exist
final parent = file.parent;
if (!(await parent.exists())) {
await parent.create(recursive: true);
}
if (contents is String) {
await file.writeAsString(contents);
} else if (contents is List<int>) {
await file.writeAsBytes(contents);
} else if (contents is Stream<List<int>>) {
return await writeStream(path, contents, options: options);
} else {
throw ArgumentError('Unsupported content type');
}
if (options != null && options.containsKey('visibility')) {
await setVisibility(path, options['visibility'] as String);
}
return true;
} catch (e) {
if (_throwsExceptions()) {
throw UnableToWriteFileException(path, cause: e);
}
return false;
}
}