Henrik is cool :)

On Thu, Sep 14, 2017 at 8:17 PM, Jimmie Houchin <jlhouc...@gmail.com> wrote:
> Thanks. I am trying to learn the ways of Pharo 6 and not use
> StandardFileStream and MultiByteFileStream. So I do not know all of the best
> ways to do things. Thanks for the education. Your "best" way worked
> perfectly in Pharo 6.
>
> Again, thanks.
>
>
> Jimmie
>
>
>
> On 09/14/2017 07:24 AM, Henrik Sperre Johansen wrote:
>>
>> Jimmie Houchin-5 wrote
>>>
>>> I still do not know how to do this correctly. But I have something that
>>> seems to work for the moment.
>>>
>>> Using #asUTF8Bytes
>>>
>>> f nextPutAll: (writer write contents asUTF8Bytes).
>>>
>>> Now the file is in UTF-8 and normal size.
>>
>>
>> openForWriteFileNamed: opens a binary stream (... which incidentally, also
>> lets you put strings/widestrings as if they were bytes/doublewords), to
>> write string source as utf8, the best way is to wrap it in a stream which
>> converts strings -> utf8 bytes, an example:
>>
>> binaryStream := (ByteArray new: 100) writeStream.
>> encodedStream := ZnCharacterWriteStream on: binaryStream encoding: #utf8.
>> encodedStream nextPutAll: '€'.
>> binaryStream contents
>>
>> The "best"* way is to use an API which provides an encoded stream with
>> scoped use (so you don't have to close it manually); for instance:
>> '/home/jimmie/xmldoc.xml' asFileReference writeStreamDo: [ :ws | ws
>> nextPutAll: writer write contents ]
>> should default to a file stream outputting utf8.
>>
>> Cheers,
>> Henry
>>
>> *May or may not work in Pharo 7 though, seeing as how the old default
>> encoded stream has been deprecated, I haven't checked.
>>
>>
>>
>> --
>> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
>>
>
>

Reply via email to