squeak-smalltalk / squeak-filesystem

FileSystem is a Smalltalk API for accessing files and directories. This is an implementation for Squeak/Smalltalk.
Other
5 stars 3 forks source link

Limited compatibility with FileStream #13

Open LinqLover opened 9 months ago

LinqLover commented 9 months ago

We noticed several compatibility issues that severely limit the applicability of FS in Squeak:

In general, the question remains how much compatibility is desired ... but I would like it ... :-)

j4yk commented 9 months ago

No standard specifies that next should return nil rather than raising an error at the end of the stream. In fact the Blue Book says this:

The reading and writing messages each determine if a next element can be read or written and, if not, an error is reported.

(pp. 196, 197, July 1985 edition)

But since "reporting an error" is a bit vague: 1. you can change the method here to return nil, 2. no code that wishes to be portable should actually rely on this behavior...

If you want to read single bytes, why not use a binary stream? If you want characters, you must think about the encoding. When in doubt, use CP1252TextConverter or ISO88591TextConverter/Latin1TextConverter.

Looking at MultiByteFileStream>>basicNext, I suppose basicBack should make sure that the position does not go below zero.

I have already given @MariusDoe my blessing to let the FS streams inherit from Stream, copy further methods from there, or whatever makes sense to address the Stream behavior that is "missing".

LinqLover commented 8 months ago

No standard specifies that next should return nil rather than raising an error at the end of the stream. In fact the Blue Book says this:

The reading and writing messages each determine if a next element can be read or written and, if not, an error is reported.

(pp. 196, 197, July 1985 edition)

But since "reporting an error" is a bit vague: 1. you can change the method here to return nil, 2. no code that wishes to be portable should actually rely on this behavior...

Oh, fair point. Though even an exact source code search for next ifNil: and then filtering results by *stream* yields 14 results ... Including TReadableStream>>#readInto:startingAt:count: :o

If you want to read single bytes, why not use a binary stream? If you want characters, you must think about the encoding. When in doubt, use CP1252TextConverter or ISO88591TextConverter/Latin1TextConverter.

Thank you! I'm actually doing both after each other: First a byte, then a string, then a number, then a character ... In default Squeak, I just can send binary and ascii many times after each other to an existing stream.

Looking at MultiByteFileStream>>basicNext, I suppose basicBack should make sure that the position does not go below zero.

+1

I have already given @MariusDoe my blessing to let the FS streams inherit from Stream, copy further methods from there, or whatever makes sense to address the Stream behavior that is "missing".

Ok, thanks for the update!