@@ -874,6 +874,19 @@ String FileAccess::get_file_as_string(const String &p_path, Error *r_error) {
874
874
return ret;
875
875
}
876
876
877
+ Error FileAccess::store_buffer_as_file (const Vector<uint8_t > &p_buffer, const String &p_path) {
878
+ Error err;
879
+ Ref<FileAccess> f = FileAccess::open (p_path, WRITE, &err);
880
+ if (f.is_null ()) {
881
+ ERR_FAIL_V_MSG (err, vformat (" Can't open file from path '%s'." , p_path));
882
+ }
883
+ return f->store_buffer (p_buffer) ? OK : ERR_FILE_CANT_WRITE;
884
+ }
885
+
886
+ Error FileAccess::store_string_as_file (const String &p_string, const String &p_path) {
887
+ return store_buffer_as_file (p_string.to_utf8_buffer (), p_path);
888
+ }
889
+
877
890
String FileAccess::get_md5 (const String &p_file) {
878
891
Ref<FileAccess> f = FileAccess::open (p_file, READ);
879
892
if (f.is_null ()) {
@@ -965,6 +978,8 @@ void FileAccess::_bind_methods() {
965
978
966
979
ClassDB::bind_static_method (" FileAccess" , D_METHOD (" get_file_as_bytes" , " path" ), &FileAccess::_get_file_as_bytes);
967
980
ClassDB::bind_static_method (" FileAccess" , D_METHOD (" get_file_as_string" , " path" ), &FileAccess::_get_file_as_string);
981
+ ClassDB::bind_static_method (" FileAccess" , D_METHOD (" store_buffer_as_file" , " buffer" , " path" ), &FileAccess::store_buffer_as_file);
982
+ ClassDB::bind_static_method (" FileAccess" , D_METHOD (" store_string_as_file" , " string" , " path" ), &FileAccess::store_string_as_file);
968
983
969
984
ClassDB::bind_method (D_METHOD (" resize" , " length" ), &FileAccess::resize);
970
985
ClassDB::bind_method (D_METHOD (" flush" ), &FileAccess::flush);
0 commit comments