FileHandle

From MiniScript Wiki
Revision as of 21:45, 5 January 2021 by JoeStrout (talk | contribs) (Created page with "In Mini Micro and command-line MiniScript, the <c>FileHandle</c> class is a small class that represents a file that has been opened for reading, writing, or updating v...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In Mini Micro and command-line MiniScript, the FileHandle class is a small class that represents a file that has been opened for reading, writing, or updating via file.open.

It provides the following methods:

Method Purpose
isOpen true if the file is still open; false after close has been called
close close the file, flushing any changes to disk
position current read/write position, in bytes from the beginning of the file
atEnd true when the current read/write position is at the end of the file
write s write a string to the file (in UTF-8 format)
writeLine s write a string to the file (in UTF-8 format), followed by a line break
read return the rest of the file, as a string (assumes UTF-8 format)
readLine return text from the current position to the next line break (assumes UTF-8)

Note that the write, writeLine, read, and readLine functions all advance the file position.