hi dears, exist the function to append data to a file?
like:
Interface.GetMod().DataFileSystem.AppendFile(myFile)
Regards
Solved Appending data to a file?
Discussion in 'Rust Development' started by modonga, Jun 4, 2016.
-
Wulf Community Admin
The Datafile API is only for JSON files, you'd simply update the file by adding new information. There aren't any other options for plugins to create other file types currently.
-
i know that other files are restricted, so no append function to JSON file?
so i need to read add new info and save again? -
A data/config file is always a single JSON value, meaning there's no point in "appending" something to the file (there can be no two JSON values in a single file). If it was any different, you wouldn't be able to serialize/deserialize JSON into a composite type.
If you're looking to create files and append to them (not read them!), you may use ConVar.Server.Log. -
Wulf Community Admin
-
excelent! thanks solve issue
-
this is my solution. Regards
string sendFile = string.Format("DataPTS");
Core.Configuration.DynamicConfigFile receiveData = Interface.GetMod().DataFileSystem.GetDatafile(sendFile);
(receiveData[section] as List<object>).Add(data); <---- THIS WORK GREAT
Interface.GetMod().DataFileSystem.SaveDatafile(sendFile); -
This is a lot more expensive than appending to a file. -
you say "A data/config file is always a single JSON value, meaning there's no point in "appending" something to the file" so this is my solution. my code dont append, only say that this is my solution to add data.
-
For Oxide, if you're looking for a persistent storage:
- that is often written to and read from, use an SQLite database.
- that should persist data between multiple servers, use a MySQL database.
- that is rarely written to and read from, use a JSON data file.
- that is used for logging, use a log file.