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

Is there a way to do .open("/file","rw")?

Started by KFAFSP, 12 June 2013 - 02:02 PM
KFAFSP #1
Posted 12 June 2013 - 04:02 PM
Hello Pros,

I have tried quite a while now to make a more efficient TFileStream implementation in my class library. Compared to a regular stream in any non-Lua file-handling mechanisms, there is a major deficit: I can't seem to open a file for both reading AND writing. If you are not familiar with the idea: normally (i.e. in Windows) files are processed as streams. You open the stream, and then you can navigate using i.e. Seek(Position) to move to a specific byte. Then you use manipulating or non-manipulating methods, like Read() or Write() which affect the selected byte and then move the "cursor" on in the file. It is a very useful option to do it like that, especially if you don't want or don't need to have the whole file in your memory.

So what I of course tried was to open a file capable of reading and writing (io.open("/file", "rw")), so that I don't have to completely store it's contents in a table first. Is that even possible in the ComputerCraft lua environment? Am I missing something here, or not ;)/> ?

Thanks in advance,
KFAFSP
Lyqyd #2
Posted 12 June 2013 - 05:07 PM
Nope. You'll need to create a new layer that loads the file into a table on first read and writes out changes when you call your close or flush method.
KFAFSP #3
Posted 13 June 2013 - 02:28 PM
Ok, thats what I already got. Thanks anyways, quite a quick response.