Kodi Community Forum

Full Version: Appending to files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there any way in xbmcvfs.File to append to a file, instead of just reading and writing. I want to write some data to the file (while downloading), close the file and then append new data to the file at a later stage.

Does anyone know if this is possible? I've also noticed that some examples of the File constructor have a third Boolean parameter:

Code:
f = xbmcvfs.File(path, 'w', True);

Does anyone know what that parameter does? It is not documented anywhere.
that's an error in our documentation. it was recently fixed.

xbmcvfs.File() doesn't have an option to append data. you would need to handle that in your addon.
Thanks ronie.

Is there a specific reason why there is no append function (or append open-mode)?

If you code this yourself, every time you append a file, you will have to copy the old file data to a new file. This is fine for small files, but if the file is 10GB this will create a huge overhead.
For appending you should use standard Python open function which supports append mode.
But Python does not natively support Samba or other network shares, or for that matter any of the other storage types that Kodi supports. So yes, for local files that would be fine, but any other files this will not work.