A FS file is a sequence [0..fileLen) of mutable bytes; the length (fileLen) of a file can be changed.
Here is what the generic stream operations do when applied to an FS file stream:
IO.GetChar: PROC [self: STREAM] RETURNS [CHAR]
Raises ERROR IO.EndOfStream[self] if the input sequence is empty; otherwise consumes and returns the next byte in the input sequence. (*)
IO.CharsAvail: PROC [self: STREAM, wait: BOOL] RETURNS [INT]
Always returns INT.LAST to indicate that all operations are done very quickly.
IO.EndOf: PROC [self: STREAM] RETURNS [BOOL]
Returns TRUE if and only if calling self.GetChar[] would raise ERROR IO.EndOfStream[self]. This means that streamIndex = fileLen. No characters are consumed. Note that if a for a read stream created from a write stream on the same file by FSExtras.StreamFromOpenStream, successive calls to IO.EndOf may return different results since the write stream may have appended or truncated the file.
IO.PutChar: PROC [self: STREAM, char: CHAR]
If used with a stream with accessRights = $read, PutChar raises IO.Error[$NotImplementedForThisStream, self]. Otherwise, if self.EndOf[] would return TRUE, then append the given byte to the output sequence modifying streamIndex and fileLen.. When self.EndOf[] would return FALSE, replace the byte at the current position, streamIndex, with the given character and advance the position. (*)
IO.Flush: PROC [self: STREAM]
If used with a stream with accessRights = $read, no action is performed on self. For write streams, all buffers containing changed data (if any) are written to the file system. Flush does not return until all writes complete. (*)
IO.Reset: PROC [self: STREAM]
streamIndex is set to fileLen. Equivalent to self.SetIndex[self.GetLength[]]. (*)
IO.Close: PROC [self: STREAM, abort: BOOL ← FALSE]
Make the stream unusable for further procedures. A self.Flush[] is performed, and many stream resources, such as buffer space, are released. If StreamOptions[closeFSOpenFileOnClose] was true when the stream was created, then the underlaying OpenFile is normally closed. If, however, other streams have been created with FSExtras.StreamFromOpenStream, then the close will be delayed until all streams that have been derived from the original StreamOpen, including the original stream, have been closed. If StreamOptions[truncatePagesOnClose] was true when the stream was created, extra pages in the file are truncated when the close of the OpenFile occurs. (*)
IO.GetIndex: PROC [self: STREAM] RETURNS [INT]
Returns the stream index.
IO.SetIndex: PROC [self: STREAM, index: INT]
Sets the stream index. Raises IO.EndOfStream if index > number of bytes in the file; does not extend the file. Raises IO.BadIndex if index is < 0. (*)
IO.GetLength: PROC [self: STREAM] RETURNS [INT]
Returns the number of bytes in the file.
IO.SetLength: PROC [self: STREAM, length: INT]
Sets the number of bytes in the file, fileLen, to length. SetLength then sets streamIndex to be MIN[streamIndex, fileLen]. The contents of the file bytes IN [previous file length .. length) are undefined. If used with a stream with accessRights = $read, PutChar raises IO.Error[$NotImplementedForThisStream, self]. If length is too large (nearly INT.LAST), then it raises IO.BadIndex. (*)