I am currently writing a logger writing to rather large log files in ILIAS for some plugin. I am using the neat new filesystem. Since the new log messages need to append to a file, I can not simply use put or update, since they seem to always truncate the logfile. Flysystem seems not to support an easy append command, so one way I found that is working is the following:
$old_data = "";
if ($DIC->filesystem()->storage()->has($this->path)) {
$old_data = $DIC->filesystem()->storage()->read($this->path);
}
$DIC->filesystem()->storage()->put($this->path, $old_data.$string);
However, this seems like very expensive regarding IO if massive amounts of data are appended to the log. I guess, this is best done using streams. I the docs (https://github.com/ILIAS-eLearning/ILIAS/tree/release_5-3/src/Filesystem) I found the following:
$webDataRoot = $DIC->filesystem()->web();
$fileStream = $webDataRoot->readStream('relative/path/to/file');
//seek at the end of the stream
$fileStream->seek($fileStream->getSize() - 1);
//append something
$fileStream->write("something");
However, with this I am getting the Can not write to a non-writable stream exception. It seems, that I would need to open the stream like so:
$resource = fopen('myPath', 'rw');
However this is specifically discouraged in the docs. What is the best way to tackle this by making use of the filesystem in ILIAS?