Legacy:Functions/Files

From Spherical
< Legacy:Functions
Revision as of 17:29, 22 May 2013 by Apollolux (talk | contribs) (created)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Files

  • RemoveFile(filename): Deletes a file.
  • GetFileList(directory): Gets an array of strings containing the filenames in 'directory'.
  • OpenFile(filename): Returns a Sphere File object with the filename.
  • OpenRawFile(filename [, writeable]): Open or create a file, and grab a RawFile handle to it.

File object

  • File.read(key, default): reads a value from the key; the value type returned depends on the default value:
    • if the default is a number, read will return a number.
    • if the default is a text or string, read will return a string.
    • if the default is a boolean, read will return a boolean
    • if the key is not present in the file, it will return the default value.
  • File.write(key, value): writes a value (string, number, boolean) to the file under the key name
  • File.flush(): writes the file to disk immediately; this way you don't have to wait for it to save when the file object is garbage collected
  • File.close(): closes the File object, after which it cannot be used anymore.
    Always remember to close opened files.

File keys

RawFile object

Size

File pointer position

Hashing raw files

  • HashFromFile(filename): Generate the MD5 'fingerprint' of a file. Identical files produce the same MD5 hash.