Difference between revisions of "Legacy:Functions/Files"
From Spherical
(created) |
(No difference)
|
Revision as of 17:29, 22 May 2013
Contents
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
- File.getNumKeys(): returns the number of keys in the file
- File.getKey(index): returns a string of the key at 'index'
RawFile object
- RawFile.read(num_bytes): Read num_bytes from the file, and return that data as a ByteArray.
- RawFile.write(byte_array): Write the data in byte_array into the file.
- RawFile.close(): Close (and flush) the RawFile object.
Size
- RawFile.getSize(): Get the size of the file in bytes.
File pointer position
- RawFile.getPosition(): Get the current position which the data is read from.
- RawFile.setPosition(position): Set the position that the file will be read from.
Hashing raw files
- HashFromFile(filename): Generate the MD5 'fingerprint' of a file. Identical files produce the same MD5 hash.