This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Zanoab's profile picture

Workaround for lack of file read-write?

Started by Zanoab, 21 October 2014 - 06:35 AM
Zanoab #1
Posted 21 October 2014 - 08:35 AM
I wrote my own serialization library based on Python's pickle library. After some thought, I wanted to take it further and add functionality to save modifications directly to file without having to rewrite the entire data set (especially large sets of thousands of objects). My plan was to analyze for changes and if the new data fits, overwrite the existing data. If not, the original will be garbaged and the new serialized data appended to the end.

My problem is that this requires extensive random access and without seek and read-write modes, I won't be able to utilize this feature in CC. Does anybody have any workarounds aside from only appending changes?
Lyqyd #2
Posted 21 October 2014 - 03:25 PM
Store a table that contains the lines of the file, exactly as they appear in the file. Modify this table as necessary, then write it out into the file when you've made changes. There isn't really a good way around it, you simply can't make small changes to a large file without writing out the whole file each time.
Zanoab #3
Posted 21 October 2014 - 05:02 PM
Thanks for the response. It is also a shame that 'a+' isn't available either to keep the file locked to avoid concurrency issues. I think I'll abandon the feature on my CC version for now.