[squeak-dev] MutliByteFileStream and CrLfFileStream (and windows)

Chris Cunningham cunningham.cb at gmail.com
Thu Aug 14 16:02:41 UTC 2014


On Thu, Aug 14, 2014 at 8:30 AM, Levente Uzonyi <leves at elte.hu> wrote:

> On Wed, 13 Aug 2014, Chris Cunningham wrote:
>
[snip]

> MultiByteFileStream changes:
>> - assume that wantsLineEndConversion is properly initialized
>> - removed the line end conversion code from #nextPut:
>>
>> Levente, do you happen to remember why you made
>> MultiByteFileStream>>nextPut: not do the line end conversion code 3 years
>> ago?
>>
>
> Because line end conversion is also done by the TextConverter (see
> #installLineEndConventionInConverter), so it created double line endings
> (cr -> crlf -> crlflf) in some cases, and it was unnecessary anyway.
>
> I just checked if it works, and it does on linux:
>
> | filename result |
> filename := UUID new asString36, '.txt'.
> FileStream newFileNamed: filename do: [ :file |
>         file
>                 lineEndConvention: #crlf;
>                 nextPut: Character cr;
>                 nextPutAll: String cr;
>                 lineEndConvention: #lf;
>                 nextPut: Character cr;
>                 nextPutAll: String cr;
>                 lineEndConvention: #cr;
>                 nextPut: Character cr;
>                 nextPutAll: String cr;
>                 lineEndConvention: nil;
>                 nextPut: Character cr;
>                 nextPutAll: String cr ].
> result := FileStream readOnlyFileNamed: filename do: [ :file | file binary
> upToEnd ].
> FileDirectory default deleteFileNamed: filename.
> self assert: result = #[13 10 13 10 10 10 13 13 13 13]
>
> Does it work on your machine?
>
> Yes, I get the same results on my system.  It appears to work just fine IF
you tell the file each time that you open it what line ending you want. So
the mechanism works.

If you let it default, however, it does not conversion at all:

| filename result |
filename := UUID new asString36, '.txt'.
FileStream newFileNamed: filename do: [ :file |
        file
                nextPut: Character cr;
                nextPutAll: String cr ].
result := FileStream readOnlyFileNamed: filename do: [ :file | file binary
upToEnd ].
FileDirectory default deleteFileNamed: filename.
self assert: result = #[13 13]

( I assume you get the same, right?)

There seem to be at least three things wrong that I see:
1. Determine the right default line endings by platform isn't happening.
 (something is going wrong with the startUp code, at least for
MultiByteFileStream).
2. The variable wantsLineEndConversion is not set.
3. The variable lineEndConvention is not set etiher.
I think these need to be fixed.  When these aren't set, it doesn't install
anything in the converter.

| filename |
filename := UUID new asString36, '.txt'.
FileStream newFileNamed: filename do: [ :file |
        self
assert: file converter notNil;
assert: file wantsLineEndConversion;
assert: file lineEndConvention notNil.
].
FileDirectory default deleteFileNamed: filename.

And, Levente, thank you for the resopnse, this helps.

-cbc

>
> Levente
>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20140814/6e0d74af/attachment.htm


More information about the Squeak-dev mailing list