Hi Sven, On 12 March 2018 at 19:38, Sven Van Caekenberghe <s...@stfx.eu> wrote: > Hi Alistair, > >> On 12 Mar 2018, at 19:06, Alistair Grant <akgrant0...@gmail.com> wrote: >> >> On 12 March 2018 at 10:03, Guillermo Polito <guillermopol...@gmail.com> >> wrote: >>> >>> Hi, >>> >>> do not forget also that there is an entire chapter on FileSystem in here: >>> >>> http://files.pharo.org/books-pdfs/deep-into-pharo/2013-DeepIntoPharo-EN.pdf >>> >>> And I particularly recommend everybody dealing with files to read about how >>> to manage encodings in here: >>> >>> http://files.pharo.org/books-pdfs/entreprise-pharo/2016-10-06-EnterprisePharo.pdf >> >> >> Cool! I wasn't aware of the section on character encoding, it's >> probably the best introduction to character encoding I've read. > > Thanks. > >> There is one important mistake in the examples. On page 46 it gives >> the following code: >> >> 'encoding-test.txt' asFileReference writeStreamDo: [ :out | >> (ZnCharacterWriteStream on: out binary encoding: #utf8) >> nextPutAll: 'Hello'; space; nextPutAll: 'Ελλάδα'; crlf; >> nextPutAll: 'Les élèves français'; crlf ]. >> >> >> This won't work reliably as #writeStreamDo: (and #readStreamDo:) use >> MultiByteFileStreams, which are not binary by default. > > It does work, you missed the #binary message sent to out.
You're right, of course. My apologies (I did miss the #binary). Cheers, Alistair >> It really should be (in Pharo 7, I haven't checked pharo 6) >> #binaryWriteStreamDo: and #binaryReadStreamDo:, i.e.: >> >> 'encoding-test.txt' asFileReference binaryWriteStreamDo: [ :out | >> (ZnCharacterWriteStream on: out binary encoding: #utf8) >> nextPutAll: 'Hello'; space; nextPutAll: 'Ελλάδα'; crlf; >> nextPutAll: 'Les élèves français'; crlf ]. > > This is indeed better (but I am not sure #binaryWriteStreamDo: was available > in the past). In this case, the #binary message sent to out should be dropped. > > Sven > >> Cheers, >> Alistair >> >> (I know I should submit a PR for this, but I'm suffering a personal >> interrupt stack overflow at the moment)