Thanks for the report. You were right, this was inconsistent, and it is now fixed: https://feedback.objo.dev/bug/1340
Just to clarify one small thing: Position and EndOfFile are properties of BinaryStream and TextStream (the streams you open from a FileSystemItem). FileSystemItem itself does not have these properties.
What happened before was:
Var stream As New BinaryStream(file)
stream.Close()
Print(stream.Position) # No exception - returned an old value
Var e As Boolean = stream.EndOfFile # Threw IOException
The reason was that Position was stored as a plain field, so it skipped the check that every other member of the stream performs. From the next release, the behaviour is uniform. After Close(), all of these throw an IOException:
stream.Position = 0 # IOException
Var p As Integer = stream.Position # IOException
Var l As Integer = stream.Length # IOException
Var e As Boolean = stream.EndOfFile # IOException
stream.ReadByte() # IOException
Two smaller changes came with this fix:
- Assigning
Position now moves the file position immediately, instead of waiting for the next read or write. For normal code this makes no difference.
- Assigning a negative value such as
stream.Position = -1 now throws InvalidArgumentException immediately, and the stream stays usable.
LittleEndian is just a setting, so you can still read and write it after closing. The same rules already applied to TextStream, so nothing changes there.
Thanks again for taking the time to report it.