Bug or feature in StandardFileStream

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug or feature in StandardFileStream

Martin Kuball
Hi!

The following behaviour seems odd to me:

file := StandardFileStream readOnlyFileNamed: 'test'.
file skip: self size.
file atEnd.  (-> true, OK)

file skip: 1.
file atEnd (-> false ???)

My VM is rather old (> 1 year), so maybe someone should test this with
a more recent one.

Martin

Reply | Threaded
Open this post in threaded view
|

Re: Bug or feature in StandardFileStream

David T. Lewis
On Sun, Feb 12, 2006 at 12:02:21PM +0100, Martin Kuball wrote:

>
> The following behaviour seems odd to me:
>
> file := StandardFileStream readOnlyFileNamed: 'test'.
> file skip: self size.
> file atEnd.  (-> true, OK)
>
> file skip: 1.
> file atEnd (-> false ???)
>
> My VM is rather old (> 1 year), so maybe someone should test this with
> a more recent one.

It's a feature. It just means that you can set the file position beyond
end of file, at which point it is no longer "atEnd". You can use
#setToEnd to position the file pointer to the actual end of file.

If it did not work this way, you would have no way to (for example)
write a single byte at position 1000 without first having written
something to the preceding 999 positions. You probably don't want
to do this very often, but at least it's possible.

It works the same on Windows and Unix, so I expect that the behavior
is consistent across all platforms.

Dave



Reply | Threaded
Open this post in threaded view
|

Re: Bug or feature in StandardFileStream

Nicolas Cellier-3
Le Dimanche 12 Février 2006 15:19, David T. Lewis a écrit :

> On Sun, Feb 12, 2006 at 12:02:21PM +0100, Martin Kuball wrote:
> > The following behaviour seems odd to me:
> >
> > file := StandardFileStream readOnlyFileNamed: 'test'.
> > file skip: self size.
> > file atEnd.  (-> true, OK)
> >
> > file skip: 1.
> > file atEnd (-> false ???)
> >
> > My VM is rather old (> 1 year), so maybe someone should test this with
> > a more recent one.
>
> It's a feature. It just means that you can set the file position beyond
> end of file, at which point it is no longer "atEnd". You can use
> #setToEnd to position the file pointer to the actual end of file.
>
> If it did not work this way, you would have no way to (for example)
> write a single byte at position 1000 without first having written
> something to the preceding 999 positions. You probably don't want
> to do this very often, but at least it's possible.
>
> It works the same on Windows and Unix, so I expect that the behavior
> is consistent across all platforms.
>
> Dave

Maybe it's a usefull feature for files opened for writing, I don't know.

But Martin had its file opened readOnly, in which case such a feature makes no
sense.

What would file next will answer? an infinite collection of zeros like a null
stream ?

Everybody would prefer getting an Exception rather than this strange behavior
i guess.


Reply | Threaded
Open this post in threaded view
|

Re: Bug or feature in StandardFileStream

David T. Lewis
On Sun, Feb 12, 2006 at 03:38:34PM +0100, nicolas cellier wrote:

> Le Dimanche 12 Février 2006 15:19, David T. Lewis a écrit :
> >
> > It's a feature. It just means that you can set the file position beyond
> > end of file, at which point it is no longer "atEnd". You can use
> > #setToEnd to position the file pointer to the actual end of file.
>
> Maybe it's a usefull feature for files opened for writing, I don't know.
>
> But Martin had its file opened readOnly, in which case such a feature makes no
> sense.
>
> What would file next will answer? an infinite collection of zeros like a null
> stream ?

It answers nil.

>
> Everybody would prefer getting an Exception rather than this strange behavior
> i guess.

Agreed.

Note the squeak file system code was written many years before the
introduction of exceptions, and there is wide agreement that it is
due for some rework. There is a team forming up to look into this:

 <http://www.squeak.org/Community/Teams/>
 <http://lists.squeakfoundation.org/pipermail/squeak-dev/2006-January/099050.html>

Dave
 

Reply | Threaded
Open this post in threaded view
|

Re: Bug or feature in StandardFileStream

Martin Kuball
Am Sunday, 12. February 2006 16:02 schrieb David T. Lewis:

> On Sun, Feb 12, 2006 at 03:38:34PM +0100, nicolas cellier wrote:
> > Le Dimanche 12 Février 2006 15:19, David T. Lewis a écrit :
> > > It's a feature. It just means that you can set the file
> > > position beyond end of file, at which point it is no longer
> > > "atEnd". You can use #setToEnd to position the file pointer to
> > > the actual end of file.
> >
> > Maybe it's a usefull feature for files opened for writing, I
> > don't know.
> >
> > But Martin had its file opened readOnly, in which case such a
> > feature makes no sense.
> >
> > What would file next will answer? an infinite collection of zeros
> > like a null stream ?
>
> It answers nil.

Well, I was afraid that this would be the answer. But that means a
read only file stream does behave different than a read stream on a
collection. And you can't use a file stream in place of a read stream
if the code does not know. So I guess I have to use something like
stream position < stream size to check if I'm still at a valid
position.

> > Everybody would prefer getting an Exception rather than this
> > strange behavior i guess.
>
> Agreed.
>
> Note the squeak file system code was written many years before the
> introduction of exceptions, and there is wide agreement that it is
> due for some rework. There is a team forming up to look into this:
>
>  <http://www.squeak.org/Community/Teams/>
>
> <http://lists.squeakfoundation.org/pipermail/squeak-dev/2006-Januar
>y/099050.html>
>
> Dave

Martin