Difference between revisions of "Legacy:Functions/Files"

From Spherical
Jump to: navigation, search
(created)
 
(Files: removed GetFileList, updated)
 
Line 1: Line 1:
 
== Files ==
 
== Files ==
  
* [[API:RemoveFile|RemoveFile]](''filename''): Deletes a file.
+
* Sphere [[API:File|File]] object is a handle to an [http://en.wikipedia.org/wiki/INI_file INI-like] key=value structured text file.
* [[API:GetFileList|GetFileList]](''directory''): Gets an array of strings containing the filenames in 'directory'.
+
* Sphere [[API:RawFile|RawFile]] object is a handle to a raw file with no inference as to structure and by default processes as binary; scripts have been written to process RawFiles according to their proper formats.
 
* [[API:OpenFile|OpenFile]](''filename''): Returns a Sphere [[API:File|File]] object with the filename.
 
* [[API:OpenFile|OpenFile]](''filename''): Returns a Sphere [[API:File|File]] object with the filename.
 
* [[API:OpenRawFile|OpenRawFile]](''filename'' [, ''writeable'']): Open or create a file, and grab a [[API:RawFile|RawFile]] handle to it.
 
* [[API:OpenRawFile|OpenRawFile]](''filename'' [, ''writeable'']): Open or create a file, and grab a [[API:RawFile|RawFile]] handle to it.

Latest revision as of 17:46, 22 May 2013

Files

  • Sphere File object is a handle to an INI-like key=value structured text file.
  • Sphere RawFile object is a handle to a raw file with no inference as to structure and by default processes as binary; scripts have been written to process RawFiles according to their proper formats.
  • 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.