ReadFile

From OxeyeWiki

Jump to: navigation, search
DaisyMoon File Objects
The ReadFile class will open a binary file for reading.

Call the ReadFile(source, mode) constructor to create a file for reading. The "source" parameter depends on the mode. If the mode is file on disk "f" or compressed file on disk "z", then the source is the file name. If the mode is in memory "m", then the source should be a WriteFile object.

Disk Example


   local path = daisy.getUserFolderPath("")
   local file = ReadFile(path .. filename, "f")

   if not file:isOk() then
      print("Unable to open " .. filename)
      return
   end

   local fileVersion = file:readInt()
   playerName = file:readString()
   -- ... and so on ...

   file:close()

In Memory Example


   gameData.savedState = WriteFile(nil, "m") -- create a memory file

   -- write a bunch of stuff
   gameData.savedState:writeInt(value)
   
   -- no need to close the file

   -- restore state...
   local readState = ReadFile(gameData.savedState, "m")

   -- read stuff
   value = readState:readInt()

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox